KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > GuiAC


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

18
19 package org.objectweb.jac.aspects.gui;
20
21 import java.lang.reflect.Array;
22 import java.text.SimpleDateFormat;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Date;
26 import java.util.Enumeration;
27 import java.util.HashMap;
28 import java.util.Hashtable;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.StringTokenizer;
33 import java.util.Vector;
34 import org.apache.log4j.Level;
35 import org.apache.log4j.Logger;
36 import org.objectweb.jac.aspects.session.SessionAC;
37 import org.objectweb.jac.core.AspectComponent;
38 import org.objectweb.jac.core.Collaboration;
39 import org.objectweb.jac.core.Display;
40 import org.objectweb.jac.core.Interaction;
41 import org.objectweb.jac.core.Jac;
42 import org.objectweb.jac.core.NameRepository;
43 import org.objectweb.jac.core.ObjectRepository;
44 import org.objectweb.jac.core.Wrappee;
45 import org.objectweb.jac.core.Wrapping;
46 import org.objectweb.jac.core.dist.Distd;
47 import org.objectweb.jac.core.dist.RemoteContainer;
48 import org.objectweb.jac.core.rtti.AbstractMethodItem;
49 import org.objectweb.jac.core.rtti.ClassItem;
50 import org.objectweb.jac.core.rtti.ClassRepository;
51 import org.objectweb.jac.core.rtti.CollectionItem;
52 import org.objectweb.jac.core.rtti.FieldItem;
53 import org.objectweb.jac.core.rtti.MemberItem;
54 import org.objectweb.jac.core.rtti.MetaItem;
55 import org.objectweb.jac.core.rtti.MethodItem;
56 import org.objectweb.jac.core.rtti.NamingConventions;
57 import org.objectweb.jac.core.rtti.NoSuchMethodException;
58 import org.objectweb.jac.core.rtti.RttiAC;
59 import org.objectweb.jac.core.rtti.VirtualClassItem;
60 import org.objectweb.jac.util.Enum;
61 import org.objectweb.jac.util.ExtArrays;
62 import org.objectweb.jac.util.ExtBoolean;
63 import org.objectweb.jac.util.InvalidIndexException;
64 import org.objectweb.jac.util.Stack;
65
66 /**
67  * This aspect component implements a very simple GUI that allows the
68  * user to browse the named object of the system and call methods on
69  * them.
70  *
71  * <p>It implements a MVC design pattern where the controllers are
72  * implemented by <code>ViewWrapper</code> instances.<p>
73  *
74  * @see ViewControlWrapper
75  * @see InputWrapper
76  * @see View
77  *
78  * @author <a HREF="mailto:renaud@cnam.fr">Renaud Pawlak</a>
79  * @author <a HREF="mailto:laurent@aopsys.com">Laurent Martelli</a>
80  */

81
82 public class GuiAC extends AspectComponent implements GuiConf {
83     static Logger logger = Logger.getLogger("gui");
84     static Logger loggerContext = Logger.getLogger("gui.context");
85     static Logger loggerDisplay = Logger.getLogger("gui.display");
86     static Logger loggerApp = Logger.getLogger("application");
87     static Logger loggerWuni = Logger.getLogger("gui.wuni");
88     static Logger loggerTable = Logger.getLogger("gui.table");
89     static Logger loggerMenu = Logger.getLogger("gui.menu");
90     static Logger loggerFactory = Logger.getLogger("gui.factory");
91
92     /** Name of the default generic object view */
93     public static final String DEFAULT_VIEW = "default";
94
95     /** Name of the autocreated object view */
96     public static final String AUTOCREATE_VIEW = "autocreate";
97
98     /** Stores the displays of the GUI (displayID -> display). */
99     protected static Hashtable displays = new Hashtable();
100
101     /** Stores the cusomized GUI (class -> display). */
102     protected static Hashtable cguis = new Hashtable();
103
104     // RTTI attributes
105
public static final String VIEWS = "GuiAC.VIEWS"; // Map String(view name) -> ObjectView
106
public static final String DEFAULTS_ATTRIBUTES_ORDER = "GuiAC.DEFAULTS_ATTRIBUTES_ORDER";
107     public static final String TREE_ATTRIBUTES_ORDER = "GuiAC.TREE_ATTRIBUTES_ORDER";
108     public static final String METHODS_ORDER = "GuiAC.METHODS_ORDER";
109     public static final String INTERACTION_HANDLER = "GuiAC.INTERACTION_HANDLER";
110     public static final String MIME_TYPE = "GuiAC.MIME_TYPE";
111
112     
113     public static final String AUTO_CREATE = "GuiAC.AUTO_CREATE"; // Boolean
114

115     public static final String AUTO_CREATE_INITIALIZER = "GuiAC.AUTO_CREATE_INITIALIZER"; // MethodItem
116
public static final String NO_AUTO_CREATE = "GuiAC.NO_AUTO_CREATE";
117     public static final String SORT_CRITERIA = "GuiAC.SORT_CRITERIA";
118     public static final String TABLE_VIEW = "GuiAC.TABLE_VIEW";
119     public static final String CHOICE_VIEW = "GuiAC.CHOICE_VIEW";
120     public static final String SHOW_ROW_NUMBERS = "GuiAC.SHOW_ROW_NUMBERS"; // Boolean
121
public static final String EDITABLE_DEFAULT_VALUES = "GuiAC.EDITABLE_DEFAULT_VALUES";
122     public static final String FILTERED_COLUMNS = "GuiAC.FILTERED_COLUMNS"; // Collection of FieldItem
123
public static final String TO_STRING = "GuiAC.TO_STRING";
124     public static final String CONTEXTUAL_TO_STRING = "GuiAC.CONTEXTUAL_TO_STRING";
125     public static final String TOOLTIP = "GuiAC.TOOLTIP";
126     public static final String CONTEXTUAL_TOOLTIP = "GuiAC.CONTEXTUAL_TOOLTIP";
127     // public static final String EMBEDDED_VIEW = "GuiAC.EMBEDDED_VIEW";
128
public static final String EMBEDDED_EDITOR = "GuiAC.EMBEDDED_EDITOR";
129     // Boolean
130
public static final String VISIBLE = "GuiAC.VISIBLE"; // Boolean
131
public static final String EDITABLE = "GuiAC.EDITABLE"; // Boolean
132
public static final String ADDABLE = "GuiAC.ADDABLE"; // Boolean
133
public static final String REMOVABLE = "GuiAC.REMOVABLE"; // Boolean
134
public static final String CREATABLE = "GuiAC.CREATABLE"; // Boolean
135

136     public static final String CATEGORIES = "GuiAC.CATEGORIES";
137     public static final String CATEGORIES_ICONS = "GuiAC.CATEGORIES_ICONS";
138     public static final String CATEGORIES_LABELS = "GuiAC.CATEGORIES_LABELS";
139     public static final String FIELD_CHOICE = "GuiAC.FIELD_CHOICE";
140     public static final String FIELD_ENUM = "GuiAC.FIELD_ENUM";
141     public static final String PARAMETER_ENUMS = "GuiAC.PARAMETER_ENUMS";
142     public static final String EDITABLE_CHOICE = "GuiAC.EDITABLE_CHOICE";
143     public static final String EDITABLE_CHOICES = "GuiAC.EDITABLE_CHOICES";
144     public static final String PARAMETER_CHOICES = "GuiAC.PARAMETER_CHOICES";
145     public static final String CLASS_CHOICES = "GuiAC.CLASS_CHOICES";
146     public static final String COLLECTION_TYPE = "GuiAC.COLLECTION_TYPE";
147     public static final String VIEW_ON_SELECTION = "GuiAC.VIEW_ON_SELECTION";
148     public static final String SELECTION_HANDLER = "GuiAC.SELECTION_HANDLER";
149     public static final String SELECTION_TARGET = "GuiAC.SELECTION_TARGET";
150     public static final String PARAMETER_NAMES = "GuiAC.PARAMETER_NAMES";
151     public static final String LINKED_PARAMETERS = "GuiAC.LINKED_PARAMETERS";
152     public static final String PASSWORD_PARAMETERS = "GuiAC.PASSWORD_PARAMETERS";
153     public static final String CREATION_ALLOWED_PARAMETERS = "GuiAC.CREATION_ALLOWED_PARAMETERS";
154     public static final String DEFAULT_VALUES = "GuiAC.DEFAULT_VALUES";
155     public static final String DYN_DEFAULT_VALUE = "GuiAC.DYN_DEFAULT_VALUE";
156     public static final String PARAMETER_FIELDS = "GuiAC.PARAMETER_FIELDS";
157     public static final String CONDITION = "GuiAC.CONDITION";
158     public static final String SLOW_OPERATION = "GuiAC.SLOW_OPERATION"; // Boolean
159
public static final String POST_INVOKE_HOOKS= "GuiAC.POST_INVOKE_HOOKS"; // List of AbstractMethodItems
160
public static final String VIEW_HEIGHT = "GuiAC.VIEW_HEIGHT"; // Length
161
public static final String VIEW_WIDTH = "GuiAC.VIEW_WIDTH"; // Length
162
public static final String EDITOR_HEIGHT = "GuiAC.EDITOR_HEIGHT"; // Length
163
public static final String EDITOR_WIDTH = "GuiAC.EDITOR_WIDTH"; // Length
164
public static final String EDITOR_SMALL_WIDTH = "GuiAC.EDITOR_SMALL_WIDTH"; // Length
165
public static final String EDITOR_SMALL_HEIGHT = "GuiAC.EDITOR_SMALL_HEIGHT"; // Length
166
public static final String HIDDEN_TREE_RELATION = "GuiAC.HIDDEN_TREE_RELATION";
167     public static final String BORDER = "GuiAC.BORDER";
168     public static final String DESCRIPTION = "GuiAC.DESCRIPTION";
169     public static final String ICON = "GuiAC.ICON";
170     public static final String DYNAMIC_ICON = "GuiAC.DYNAMIC_ICON";
171     public static final String MENU = "GuiAC.MENU";
172     public static final String DISPLAY_LABEL = "GuiAC.DISPLAY_LABEL"; // boolean
173
public static final String LABEL = "GuiAC.LABEL"; // String
174
public static final String MNEMONICS = "GuiAC.MNEMONICS"; // String
175
public static final String CONTEXTUAL_LABEL = "GuiAC.CONTEXTUAL_LABEL";
176     public static final String STYLE = "GuiAC.STYLE"; // String
177
public static final String NEW_WINDOW = "GuiAC.NEW_WINDOW";
178     public static final String NUM_ROWS_PER_PAGE = "GuiAC.NUM_ROWS_PER_PAGE"; // int
179
public static final String AVAILABLE_NUM_ROWS_PER_PAGE = "GuiAC.AVAILABLE_NUM_ROWS_PER_PAGE"; // int[]
180
public static final String AUTO_CREATED_STATE = "GuiAC.AUTO_CREATED_STATE";
181     public static final String SMALL_TARGET_CONTAINER = "GuiAC.SMALL_TARGET_CONTAINER";
182     public static final String NAVBAR = "GuiAC.NAVBAR";
183     public static final String FIELD_DEPENDENCIES = "GuiAC.FIELD_DEPENDENCIES";
184     public static final String LINE_BREAKS = "GuiAC.LINE_BREAKS";
185     public static final String DIRECT_COLLECTION_METHODS = "GuiAC.DIRECT_COLLECTION_METHODS";
186     public static final String DATE_FORMAT = "GuiAC.DATE_FORMAT";
187     public static final String DATEHOUR_FORMAT = "GuiAC.DATEHOUR_FORMAT";
188     public static final String FLOAT_FORMAT = "GuiAC.FLOATFORMAT";
189     public static final String INT_FORMAT = "GuiAC.INT_FORMAT";
190     public static final String FORMAT = "GuiAC.FORMAT";
191
192     public static final String ASKING_SEQUENCE = "GuiAC.ASKING_SEQUENCE";
193
194     public static final String DESKTOP_VIEW = "GuiAC.DESKTOP_VIEW"; //ClassItem
195
public static final String FILE_SELECTION_MODE =
196     "GuiAC.FILE_SELECTION_MODE";
197     // String
198
public static final String FILE_EXTENSIONS = "GuiAC.FILE_EXTENSIONS";
199     // String[]
200
public static final String FILE_EXTENSIONS_DESCRIPTION =
201     "GuiAC.FILE_EXTENSIONS_DESCRIPTION";
202     // String
203
public static final String FILE_CHOOSER_VIEW = "GuiAC.FILE_CHOOSER_VIEW";
204     public static final String FILE_EDITOR_CONFIG = "GuiAC.FILE_EDITOR_CONFIG";
205
206     public static final String INDEXED_FIELD_SELECTOR =
207     "GuiAC.INDEXED_FIELD_SELECTOR";
208     // CollectionItem
209
public static final String INDEX_NOT_FOUND_HANDLER =
210     "RttiAC.INDEX_NOT_FOUND_HANDLER";
211     // MethodItem
212

213     public static final String REPOSITORY_NAME = "GuiAC.REPOSITORY_NAME";
214
215     // Context attributes
216

217     public static final String DISPLAY_CONTEXT = "GuiAC.DISPLAY";
218     /** A "concrete" method we should ask parameters for */
219     public static final String ASK_FOR_PARAMETERS = "GuiAC.ASK_FOR_PARAMETERS";
220     /** The "not concrete" method we should ask parameters for */
221     public static final String INVOKED_METHOD = "GuiAC.INVOKED_METHOD";
222     public static final String AUTO_CREATION = "GuiAC.AUTO_CREATION";
223     public static final String AUTOCREATE_REASON = "GuiAC.AUTOCREATE_REASON";
224     // Boolean
225
/** Boolean value to force the use of embedded editors. Defaults to false. */
226     //public static final String EMBEDDED_EDITORS = "GuiAC.EMBEDDED_EDITORS";
227
// Boolean
228
public static final String SMALL_VIEW = "GuiAC.SMALL_VIEW"; // Boolean
229
public static final String OPPOSITE_ROLE = "GuiAC.OPPOSITE_ROLE";
230     // FieldItem
231
public static final String VIEW = "GuiAC.VIEW";
232     public static final String OPEN_VIEW = "GuiAC.OPEN_VIEW"; // Boolean
233
public static final String GRAPHIC_CONTEXT = "GuiAC.GRAPHIC_CONTEXT";
234
235     /** Start index in a collection view Map (CollectionItem -> Integer) */
236     public static final String START_INDEXES = "GuiAC.START_INDEXES";
237
238     public static final int THUMB_MAX_WIDTH = 100;
239     public static final int THUMB_MAX_HEIGHT = 50;
240     public static final int THUMB_QUALITY = 70;
241
242     // Map: CollectionItem -> column index
243
public static final String SORT_COLUMN = "GuiAC.SORT_COLUMN"; // [+-]?<fieldname>
244
public static final String DEF_SORT = "GuiAC.DEF_SORT";
245
246     // Map: CollectionItem -> ColumnFilter
247
public static final String TABLE_FILTER = "GuiAC.TABLE_FILTER";
248     
249
250     /** Disable commit in editors */
251     //public static final String NO_COMMIT = "GuiAC.NO_COMMIT";
252

253     /** Substance on which the method is invoked. Set when auto creating parameters */
254     public static final String SUBSTANCE = "GuiAC.SUBSTANCE"; // Wrappee
255

256     /** TreeNode being removed, to optimize Tree refresh */
257     public static final String REMOVED_NODE = "GuiAC.REMOVED_NODE";
258
259     static String parseFormatExpression(
260         String formatExpr,
261         Object o,
262         String beforeString,
263         String afterString)
264     {
265         final String delim = "%";
266         StringBuffer result = new StringBuffer();
267         String subString = null;
268         ClassItem cl = ClassRepository.get().getClass(o);
269         StringTokenizer st = new StringTokenizer(formatExpr, delim, true);
270         while (st.hasMoreTokens()) {
271             boolean firstDelim = false;
272             String cur = st.nextToken();
273             // normal string
274
if (!cur.equals(delim)) {
275                 result.append(cur);
276                 continue;
277             }
278             // delimited expression
279
if (cur.equals(delim)) {
280                 cur = st.nextToken();
281                                 // double delim
282
if (cur.equals(delim)) {
283                     result.append(delim);
284                     continue;
285                 }
286                 if (cur.indexOf("()") == -1) {
287                     // field name
288
try {
289                         FieldItem field = cl.getField(cur);
290                         Object value = field.getThroughAccessor(o);
291                         if (beforeString != null) {
292                             result.append(beforeString);
293                         }
294                         if (field != null)
295                             result.append(GuiAC.toString(field, value));
296                         else
297                             result.append("<bad field: " + cur + ">");
298                         if (afterString != null) {
299                             result.append(afterString);
300                         }
301                     } catch (Exception e) {
302                         // bad field description
303
result.append("<bad field: " + cur + ">");
304                     }
305                 } else {
306                     // method with no args
307
try {
308                         Object value =
309                             ClassRepository.invokeDirect(
310                                 cl.getActualClass(),
311                                 cur.substring(0, cur.length() - 2),
312                                 o,
313                                 ExtArrays.emptyObjectArray);
314                         ;
315                         if (beforeString != null) {
316                             result.append(beforeString);
317                         }
318                         result.append(GuiAC.toString(value));
319                         if (afterString != null) {
320                             result.append(afterString);
321                         }
322                     } catch (Exception e) {
323                         // bad method description
324
result.append(
325                             "<bad method: "
326                             + cur.substring(0, cur.length() - 2)
327                             + ">");
328                     }
329                 }
330                                 // read closing delim
331
cur = st.nextToken();
332             }
333         }
334         return result.toString();
335     }
336
337     public static String toString(Object o) {
338         return toString(o, null);
339     }
340
341     public static String toString(float value) {
342         return toString(new Float(value), null);
343     }
344
345     public static String toString(double value) {
346         return toString(new Double(value), null);
347     }
348
349     /**
350      * Gets the string representation of an object.
351      * @param o the object
352      * @return a string representing the object o
353      * @see #setToString(ClassItem,String)
354      */

355     public static String toString(Object o, Stack context) {
356         if (o == null)
357             return "null";
358         ClassItem cl = ClassRepository.get().getClass(o);
359
360         String formatExpr = (String) cl.getAttribute(TO_STRING);
361         if (context != null) {
362             formatExpr =
363                 (String) getContextAttribute(cl,
364                                              CONTEXTUAL_TO_STRING,
365                                              context,
366                                              formatExpr);
367         }
368         if (formatExpr == null) {
369             if (o instanceof java.awt.Point) {
370                 java.awt.Point p = (java.awt.Point) o;
371                 return "(" + p.x + "," + p.y + ")";
372             } else if (o instanceof java.awt.Dimension) {
373                 java.awt.Dimension d = (java.awt.Dimension) o;
374                 return d.width + "x" + d.height;
375             } else if (o instanceof Date) {
376                 return new SimpleDateFormat(getDateFormat()).format((Date) o);
377             } else if (o instanceof Collection) {
378                 String string = "";
379                 Iterator it = ((Collection) o).iterator();
380                 while (it.hasNext()) {
381                     string += toString(it.next(), context);
382                     if (it.hasNext())
383                         string += ", ";
384                 }
385                 return string;
386             } else if (o instanceof Wrappee) {
387                 return NameRepository.get().getName(o);
388             } else {
389                 return o.toString();
390             }
391         } else {
392             return parseFormatExpression(formatExpr, o, null, null);
393         }
394     }
395
396     /**
397      * Gets the tooltip text of an object.
398      * @param context a stack of meta items representing the context
399      * @param o the object
400      * @return the tooltip of the object in the given context
401      * @see #setToolTipText(ClassItem,String)
402      */

403     public static String getToolTip(Object o, Stack context) {
404         if (o == null)
405             return null;
406         ClassItem cl = ClassRepository.get().getClass(o);
407
408         String formatExpr = (String) cl.getAttribute(TOOLTIP);
409         if (context != null) {
410             formatExpr =
411                 (String) getContextAttribute(cl,
412                                              CONTEXTUAL_TOOLTIP,
413                                              context,
414                                              formatExpr);
415         }
416         if (formatExpr == null) {
417             return null;
418         } else {
419             return parseFormatExpression(formatExpr, o, null, null);
420         }
421     }
422
423     /**
424      * @param item item holding the rules
425      * @param attribute name of attribute holding the rules
426      * @param defaultValue this value is returned if there is not matching context
427      */

428     public static Object getContextAttribute(
429         MetaItem item,
430         String attribute,
431         Stack context,
432         Object defaultValue)
433     {
434         loggerContext.debug("getContextAttribute " + item + "," + attribute);
435         Map rules = (Map) item.getAttribute(attribute);
436         if (rules == null) {
437             loggerContext.debug("No attribute " + attribute);
438             return defaultValue;
439         } else {
440             if (context != null) {
441                 loggerContext.debug("rules = " + rules);
442                 for (int i = 0; i < context.size(); i++) {
443                     MetaItem elt = (MetaItem) context.peek(i);
444                     Iterator it = rules.keySet().iterator();
445                     while (it.hasNext()) {
446                         MetaItem selector = (MetaItem) it.next();
447                         if (selector instanceof ClassItem) {
448                             ClassItem cl = (ClassItem) selector;
449                             if ((elt instanceof ClassItem
450                                  && ((ClassItem) elt).isSubClassOf(cl))
451                                 || (elt instanceof MemberItem
452                                     && ((MemberItem) elt)
453                                     .getClassItem()
454                                     .isSubClassOf(cl))) {
455                                 loggerContext.debug(elt + " matches " + selector
456                                     + " -> " + rules.get(selector));
457                                 return rules.get(selector);
458                             }
459                         } else if (selector instanceof MemberItem) {
460                             MemberItem member = (MemberItem) selector;
461                             if (elt instanceof MemberItem) {
462                                 if (((MemberItem) elt)
463                                     .getClassItem()
464                                     .isSubClassOf(member.getClassItem())
465                                     && member.getName().equals(elt.getName())) {
466                                     loggerContext.debug(elt + " matches " + selector
467                                         + " -> " + rules.get(selector));
468                                     return rules.get(selector);
469                                 }
470                             }
471                         }
472                     }
473                 }
474                 return defaultValue;
475             } else {
476                 loggerContext.debug("No graphic context");
477                 return defaultValue;
478             }
479         }
480     }
481
482     public static void pushGraphicContext(MetaItem value) {
483         Collaboration collab = Collaboration.get();
484         Stack gc = (Stack) collab.getAttribute(GRAPHIC_CONTEXT);
485         if (gc == null) {
486             gc = new Stack();
487             collab.addAttribute(GRAPHIC_CONTEXT, gc);
488         }
489         loggerContext.debug("push " + value);
490         gc.push(value);
491     }
492
493     public static MetaItem popGraphicContext() {
494         Stack gc = (Stack) Collaboration.get().getAttribute(GRAPHIC_CONTEXT);
495         if (gc == null) {
496             loggerContext.error(
497                 "No GRAPHIC_CONTEXT in current context, cannot popGraphicContext");
498             return null;
499         } else {
500             loggerContext.debug("pop " + gc.peek());
501             return (MetaItem) gc.pop();
502         }
503     }
504
505     public static Stack getGraphicContext() {
506         return (Stack) Collaboration.get().getAttribute(GRAPHIC_CONTEXT);
507     }
508
509     /**
510      * Gets the string representation of the field of an object.
511      * @param field the field
512      * @param value the value of the field
513      * @return a string representing the value of the field
514      */

515     public static String toString(FieldItem field, Object value) {
516         if (value == null) {
517             return "null";
518         }
519         Enum enum = getEnum(field);
520         if (enum != null) {
521             try {
522                 return value != null
523                     ? enum.int2string(((Integer) value).intValue())
524                     : "";
525             } catch (InvalidIndexException e) {
526                 return "";
527             }
528         } else if (value instanceof Date) {
529             return new SimpleDateFormat(getDateFormat()).format((Date) value);
530         } else {
531             return toString(value);
532         }
533     }
534
535     /**
536      * Gets the string representation of the field of an object.
537      * @param field the field
538      * @param value the value of the field
539      * @return a string representing the value of the field
540      */

541     public static String toString(FieldItem field, int value) {
542         return toString(field, new Integer(value));
543     }
544
545     /**
546      * Gets a display from its ID.
547      *
548      * @param displayID the id of the display
549      * @see Display */

550
551     public static final Display getDisplay(String displayID) {
552         return (Display) displays.get(displayID);
553     }
554
555     /**
556      * Gets a display from its ID.
557      *
558      * @param customizedID the id of the customized gui
559      * @see Display
560      */

561     public static final CustomizedGUI getCustomized(String customizedID) {
562         return (CustomizedGUI) cguis.get(customizedID);
563     }
564
565     /**
566      * Creates a new display and registers it.
567      *
568      * @param displayID the display name
569      * @param displayType the display class to instantiate. It must
570      * have a constructor taking a ViewFactory parameter
571      * @param factory the view factory for the display
572      */

573     public static Display createDisplay(String displayID,
574                                         Class displayType,
575                                         ViewFactory factory)
576         throws Exception
577     {
578         Display ret = null;
579         loggerDisplay.debug("createDisplay(" + displayType.getName() + "," + displayType + ")");
580         if ((ret = getDisplay(displayID)) != null) {
581             loggerDisplay.warn("Display " + displayID + " is already registered");
582             return ret;
583         }
584         try {
585             ret =
586                 (Display) displayType
587                 .getDeclaredConstructor(new Class[] { ViewFactory.class })
588                 .newInstance(new Object[] { factory });
589
590             ret.setDisplayID(displayID);
591             addDisplay(displayID, ret);
592         } catch (Exception e) {
593             logger.error(
594                 "createDisplay("+displayID+","+
595                 displayType.getName()+","+factory+
596                 ") failed to instantiate display: "+e);
597             throw e;
598         }
599         return ret;
600     }
601
602     public void createSwingDisplays(String[] customizedIDs) {
603         loggerDisplay.debug("createSwingDisplays(" + Arrays.asList(customizedIDs) + ")");
604         for (int i=0; i<customizedIDs.length; i++) {
605             try {
606                 if (customizedIDs[i].equals("admin")) {
607                 // createDisplay("admin",org.objectweb.jac.aspects.gui.swing.ProgramView.class,null);
608
} else {
609                     showCustomizedSwing(customizedIDs[i], customizedIDs[i]);
610                 }
611             } catch(Exception e) {
612                 logger.error("Failed to create swing display \""+customizedIDs[i]+'"',e);
613             }
614         }
615     }
616
617     public void createWebDisplays(String[] customizedIDs) {
618         int port = 8088;
619         try {
620             logger.info(
621                 "createWebDisplays "+Arrays.asList(customizedIDs)+
622                 " for application " + application);
623             org.objectweb.jac.aspects.gui.web.WebDisplay.startWebServer(
624                 application,
625                 customizedIDs,
626                 port);
627         } catch (Exception e) {
628             loggerDisplay.error("Failed to start webgui : " + e);
629             loggerDisplay.error("Check that another server is not running on port " + port);
630         }
631     }
632
633     /**
634      * Adds a new display for this GUI.
635      *
636      * @param newDisplay the display to add
637      * @see Display
638      */

639     public static void addDisplay(String displayID, Display newDisplay) {
640         loggerDisplay.debug("addDisplay(" + newDisplay.getClass().getName() + ")");
641         displays.put(displayID, newDisplay);
642     }
643
644     /**
645      * Removes a display for this GUI.
646      *
647      * @param display the display to remove
648      * @see Display */

649
650     public static void removeDisplay(Display display) {
651         if (display.getDisplayID() != null)
652             displays.remove(display.getDisplayID());
653     }
654
655     /**
656      * This configuration method allows the user to register a new
657      * display.
658      *
659      * <p>It instantiates a new display from its class name and
660      * registers its.
661      *
662      * @param name the display name
663      * @param displayType the display type
664      * @param guiType the type of the gui (
665      */

666     public static void registerDisplay(String name,
667                                        String displayType,
668                                        String guiType)
669         throws Exception
670     {
671         if (getDisplay(name) != null) {
672             loggerDisplay.warn("display " + name + " is already launched");
673             return;
674         }
675         createDisplay(
676             name,
677             Class.forName(displayType),
678             getViewFactory(guiType));
679     }
680
681     public void registerCustomized(String name) {
682         try {
683             if (getCustomized(name) != null) {
684                 warning("customized GUI " + name + " is already registered");
685                 return;
686             }
687             CustomizedGUI cgui = new CustomizedGUI(name);
688             // the customized gui knows the application it belongs to
689
loggerApp.debug("customized gui " + name
690                             + " belongs to " + Collaboration.get().getCurApp());
691             cgui.setApplication(Collaboration.get().getCurApp());
692             cguis.put(name, cgui);
693         } catch (Exception e) {
694             e.printStackTrace();
695         }
696     }
697
698     public void showCustomizedSwing(String displayName,
699                                     String gui,
700                                     String host)
701         throws Exception
702     {
703         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
704         if (cgui == null) {
705             error(gui+" has not been declared with registerCustomized. "+
706                   "Available customized GUI: " + cguis.keySet());
707             return;
708         }
709         if (host == null
710             || RemoteContainer.resolve(host) == null
711             || RemoteContainer.resolve(host).getName().equals(
712                 Distd.getLocalContainerName()))
713         {
714             registerDisplay(
715                 displayName,
716                 "org.objectweb.jac.aspects.gui.swing.SwingDisplay",
717                 "swing");
718
719             Display swingGUI = getDisplay(displayName);
720             Collaboration.get().addAttribute(
721                 DISPLAY_CONTEXT,
722                 new DisplayContext((CustomizedDisplay) swingGUI, null));
723             Collaboration.get().addAttribute(
724                 SessionAC.SESSION_ID,
725                 GuiAC.getLocalSessionID());
726             swingGUI.showCustomized(gui, cgui);
727             //swingGUI.applicationStarted();
728
} else {
729             displays.remove(gui);
730         }
731         // ((ACManager)ACManager.get()).afterApplicationStarted();
732
}
733
734     public void showCustomizedSwing(String displayName, String gui)
735         throws Exception
736     {
737         showCustomizedSwing(displayName, gui, null);
738     }
739
740     public void setWelcomeMessage(
741         String gui,
742         String title,
743         String message,
744         String icon)
745     {
746         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
747         if (cgui == null) {
748             error(gui+" has not been declared with registerCustomized");
749             return;
750         }
751         cgui.setWelcomeMessage(title, message, icon);
752     }
753
754     public void setStyle(FieldItem field, String style) {
755         if (style != null) {
756             field.setAttribute(STYLE, style);
757         }
758     }
759
760     public void setStyle(ClassItem cli, String style) {
761         if (style != null) {
762             cli.setAttribute(STYLE, style);
763         }
764     }
765
766     public void setOnCloseHandler(
767         String gui,
768         AbstractMethodItem eventHandler)
769     {
770         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
771         if (cgui == null) {
772             error(gui+" has not been declared with registerCustomized");
773             return;
774         }
775         cgui.setOnCloseHandler(eventHandler);
776     }
777
778     public void addStatusBar(String gui, MethodItem method, String position) {
779         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
780         if (cgui == null) {
781             error(gui+" has not been declared with registerCustomized");
782             return;
783         }
784         cgui.addStatusBar(method, position);
785     }
786
787     public void addStatusBar(String gui, String position) {
788         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
789         if (cgui == null) {
790             error(gui+" has not been declared with registerCustomized");
791             return;
792         }
793         cgui.addStatusBar(null, position);
794     }
795
796     public void setSubPanesGeometry(
797         String gui,
798         int subPanesCount,
799         String geometry)
800     {
801         boolean[] scrollings = new boolean[subPanesCount];
802         Arrays.fill(scrollings, true);
803         setSubPanesGeometry(gui, subPanesCount, geometry, scrollings);
804     }
805
806     public void setSubPanesGeometry(
807         String gui,
808         int subPanesCount,
809         String geometry,
810         boolean[] scrollings)
811     {
812         if (subPanesCount != scrollings.length) {
813             throw new RuntimeException("setSubPanesGeometry: subPanesCount!=scrollings.length");
814         }
815         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
816         if (cgui == null) {
817             logger.error(gui+" has not been declared with registerCustomized");
818             return;
819         }
820         int geom = 0;
821         if (geometry.compareToIgnoreCase("VERTICAL")==0)
822             geom = CustomizedGUI.VERTICAL;
823         else if (geometry.compareToIgnoreCase("VERTICAL_LEFT")==0)
824             geom = CustomizedGUI.VERTICAL_LEFT;
825         else if (geometry.compareToIgnoreCase("VERTICAL_RIGHT")==0)
826             geom = CustomizedGUI.VERTICAL_RIGHT;
827         else if (geometry.compareToIgnoreCase("HORIZONTAL")==0)
828             geom = CustomizedGUI.HORIZONTAL;
829         else if (geometry.compareToIgnoreCase("HORIZONTAL_UP")==0)
830             geom = CustomizedGUI.HORIZONTAL_UP;
831         else if (geometry.compareToIgnoreCase("HORIZONTAL_DOWN")==0)
832             geom = CustomizedGUI.HORIZONTAL_DOWN;
833         else if (geometry.compareToIgnoreCase("NONE")==0)
834             geom = CustomizedGUI.HORIZONTAL;
835         else
836             warning("Unknown geometry '"+geometry+"'");
837         cgui.setSubPanesGeometry(subPanesCount, geom, scrollings);
838     }
839
840     public void setPaneContent(
841         String gui,
842         String paneId,
843         String type,
844         String[] args)
845     {
846         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
847         if (cgui == null) {
848             error(gui+" has not been declared with registerCustomized");
849             return;
850         }
851         cgui.setPaneContent(paneId, type, args);
852     }
853
854     public void setPaneContainer(String gui, String paneId, String type) {
855         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
856         if (cgui == null) {
857             error(gui+" has not been declared with registerCustomized");
858             return;
859         }
860         cgui.setPaneContainer(paneId, type);
861     }
862
863     public void setInvalidPane(
864         String gui,
865         String changedPane,
866         String invalidPane)
867     {
868         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
869         if (cgui == null) {
870             error(gui+" has not been declared with registerCustomized");
871             return;
872         }
873         cgui.setInvalidPane(changedPane, invalidPane);
874     }
875
876     public void addReferenceToPane(
877         String gui,
878         MemberItem field,
879         String panePath)
880     {
881         addReferenceToPane(
882             gui,
883             field,
884             "Object",
885             new String[] { DEFAULT_VIEW },
886             Boolean.FALSE,
887             panePath);
888     }
889
890     public void addReferenceToPane(
891         String gui,
892         MemberItem member,
893         String viewType,
894         String[] viewParams,
895         Boolean small,
896         String paneId)
897     {
898         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
899         if (cgui == null) {
900             error(gui+" has not been declared with registerCustomized");
901             return;
902         }
903         member.setAttribute(SMALL_TARGET_CONTAINER, small);
904         cgui.addReferenceToPane(member, viewType, viewParams, paneId);
905     }
906
907     public void newWindow(String gui, String className, String fieldName) {
908
909         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
910         if (cgui == null) {
911             error(gui+" has not been declared with registerCustomized");
912             return;
913         }
914         ClassItem cli = ClassRepository.get().getClass(className);
915         FieldItem field = cli.getField(fieldName);
916         field.setAttribute(NEW_WINDOW, gui);
917     }
918
919     public void setCustomizedIcon(String gui, String icon) {
920         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
921         if (cgui == null) {
922             error(gui+" has not been declared with registerCustomized");
923             return;
924         }
925         cgui.setIcon(icon);
926     }
927
928     public void setPosition(
929         String gui,
930         int left,
931         int up,
932         int width,
933         int height)
934     {
935         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
936         if (cgui == null) {
937             error(gui+" has not been declared with registerCustomized");
938             return;
939         }
940         cgui.setPosition(left, up, width, height);
941     }
942
943     public void addMenuItem(
944         String gui,
945         String menu,
946         String[] menuPath,
947         AbstractMethodItem callback)
948     {
949         addMenuItem(gui, menu, menuPath, null, callback, null);
950     }
951
952     public void addMenuItem(
953         String gui,
954         String menu,
955         String[] menuPath,
956         String objectName,
957         AbstractMethodItem callback)
958     {
959         addMenuItem(gui, menu, menuPath, objectName, callback, null);
960     }
961
962     public void addMenuItem(
963         String gui,
964         String menu,
965         String[] menuPath,
966         AbstractMethodItem callback,
967         String[] parameters)
968     {
969         addMenuItem(gui, menu, menuPath, null, callback, parameters);
970     }
971
972     public void addMenuItem(
973         String gui,
974         String menu,
975         String[] menuPath,
976         String objectName,
977         AbstractMethodItem callback,
978         String[] parameters)
979     {
980         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
981         if (cgui == null) {
982             error(gui+" has not been declared with registerCustomized");
983             return;
984         }
985         cgui.addMenuItem(
986             menu,
987             menuPath,
988             new Callback(objectName, callback, parameters));
989     }
990
991     public void addMenuSeparator(String gui, String menu, String[] menuPath) {
992         CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
993         if (cgui == null) {
994             error(gui+" has not been declared with registerCustomized");
995             return;
996         }
997         cgui.addMenuSeparator(menu, menuPath);
998     }
999
1000    public void setMenuPosition(String gui, String menu, String position) {
1001        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1002        if (cgui == null) {
1003            error(gui+" has not been declared with registerCustomized");
1004            return;
1005        }
1006        cgui.setMenuPosition(menu, position);
1007    }
1008
1009    public void setMenuIcon(
1010        String gui,
1011        String menu,
1012        String[] menuPath,
1013        String icon)
1014    {
1015        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1016        if (cgui == null) {
1017            error(gui+" has not been declared with registerCustomized");
1018            return;
1019        }
1020        cgui.setMenuIcon(menu, menuPath, ResourceManager.getResource(icon));
1021    }
1022
1023    public void addToolbarAction(String gui, AbstractMethodItem method) {
1024        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1025        if (cgui == null) {
1026            error(gui+" has not been declared with registerCustomized");
1027            return;
1028        }
1029        cgui.addToolbarAction(method);
1030    }
1031
1032    public void addToolbarAction(
1033        String gui,
1034        String objectName,
1035        AbstractMethodItem method)
1036    {
1037        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1038        if (cgui == null) {
1039            error(gui+" has not been declared with registerCustomized");
1040            return;
1041        }
1042        cgui.addToolbarAction(objectName, method);
1043    }
1044
1045    public void addToolbarAction(
1046        String gui,
1047        AbstractMethodItem method,
1048        String[] params)
1049    {
1050        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1051        if (cgui == null) {
1052            error(gui+" has not been declared with registerCustomized");
1053            return;
1054        }
1055        cgui.addToolbarAction(null,method,params);
1056    }
1057
1058    public void addToolbarSeparator(String gui) {
1059        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1060        if (cgui == null) {
1061            error(gui+" has not been declared with registerCustomized");
1062            return;
1063        }
1064        cgui.addToolbarSeparator();
1065    }
1066
1067    public void setSplitterLocation(
1068        String gui,
1069        int splitterId,
1070        float location)
1071    {
1072        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1073        if (cgui == null) {
1074            error(gui+" has not been declared with registerCustomized");
1075            return;
1076        }
1077        cgui.setSplitterLocation(splitterId, location);
1078    }
1079
1080    public void setTitle(String gui, String title) {
1081        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1082        if (cgui == null) {
1083            error(gui+" has not been declared with registerCustomized");
1084            return;
1085        }
1086        cgui.setTitle(title);
1087    }
1088
1089    public void addStyleSheetURL(String gui, String url) {
1090        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1091        if (cgui == null) {
1092            error(gui+" has not been declared with registerCustomized");
1093            return;
1094        }
1095        cgui.addStyleSheetURL(url);
1096    }
1097
1098    static Vector cssURLs = new Vector();
1099    public void addStyleSheetURL(String url) {
1100        cssURLs.add(url);
1101    }
1102    static public Vector getStyleSheetURLs() {
1103        return cssURLs;
1104    }
1105
1106    public void setLoggingMethod(
1107        String gui,
1108        String objects,
1109        String classes,
1110        String methods,
1111        int paneID)
1112    {
1113        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
1114        if (cgui == null) {
1115            error(gui+" has not been declared with registerCustomized");
1116            return;
1117        }
1118        /*
1119          JPanel pane = cgui.getPane(paneID);
1120          JTextArea textArea = new JTextArea();
1121          pane.add(textArea);
1122          pointcut( objects, classes, methods,
1123          new LoggingWrapper(textArea),
1124          "logIntoConsole");
1125        */

1126    }
1127
1128    /**
1129     * The wrapper that logs methods into a Swing console. */

1130    /*
1131      public class LoggingWrapper extends Wrapper {
1132      JTextArea console;
1133      public LoggingWrapper(JTextArea console) {
1134      this.console = console;
1135      }
1136      public Object logIntoConsole() {
1137      if( console != null ) {
1138      console.append( (String)arg(0) );
1139      console.setCaretPosition( console.getText().length() );
1140      }
1141      return proceed();
1142      }
1143      }
1144    */

1145
1146    public void defineResource(String type, String name, String path) {
1147        ResourceManager.defineResource(name, path);
1148    }
1149
1150    public void setIcon(ClassItem cli, String name) {
1151        cli.setAttribute(ICON, ResourceManager.getResource(name));
1152    }
1153
1154    public void setIcon(MemberItem member, String name) {
1155        member.setAttribute(ICON, ResourceManager.getResource(name));
1156    }
1157
1158    public void setDynamicIcon(MethodItem method, MethodItem iconMethod) {
1159        method.setAttribute(DYNAMIC_ICON, iconMethod);
1160    }
1161
1162    public void setDynamicIcon(ClassItem cli, MethodItem iconMethod) {
1163        cli.setAttribute(DYNAMIC_ICON, iconMethod);
1164    }
1165
1166    /**
1167     * Returns the icon associated with this item. If no icon was set
1168     * with one the of setIcon() configuration methods, we try to
1169     * return a reasonable default.
1170     *
1171     * @see #setIcon(ClassItem,String)
1172     * @see #setIcon(MemberItem,String)
1173     */

1174    public static String getIcon(MetaItem item) {
1175        String result = (String)item.getAttribute(ICON);
1176        if (result == null) {
1177            if (item instanceof MethodItem) {
1178                MethodItem method = (MethodItem)item;
1179                if (method.isSetter()) {
1180                    result = ResourceManager.getResource("edit_icon");
1181                } else if (method.isAdder()) {
1182                    if (method.getParameterTypes().length > 0) {
1183                        result =
1184                            getIcon(
1185                                ClassRepository.get().getClass(
1186                                    method.getParameterTypes()[0]));
1187                    }
1188                    if (result == null)
1189                        result = ResourceManager.getResource("new_icon");
1190                } else if (method.isRemover()) {
1191                    result = ResourceManager.getResource("remove_icon");
1192                }
1193            }
1194        }
1195        return result;
1196    }
1197
1198    /**
1199     * Gets an icon for an object
1200     * @param cli the class of the object
1201     * @param object the object
1202     * @return an icon's resource name
1203     */

1204    public static String getIcon(ClassItem cli, Object object) {
1205        MethodItem dynIcon = (MethodItem)cli.getAttribute(DYNAMIC_ICON);
1206        String icon = null;
1207        if (dynIcon!=null) {
1208            icon = (String)dynIcon.invokeStatic(new Object[] {object});
1209        }
1210        if (icon==null)
1211            icon = (String)cli.getAttribute(ICON);
1212        return icon;
1213    }
1214
1215    public static String getIcon(Callback callback) {
1216        AbstractMethodItem method = callback.getMethod();
1217        String icon =
1218            method != null ? GuiAC.getIcon(method) : null;
1219        if (method != null) {
1220            MethodItem dynIcon = (MethodItem)method.getAttribute(DYNAMIC_ICON);
1221            if (dynIcon!=null) {
1222                icon = (String)dynIcon.invokeStatic(
1223                    new Object[] {
1224                        method,
1225                        callback.getObject(),
1226                        callback.getParameters()});
1227            }
1228        }
1229        if (icon == null) {
1230            icon = ResourceManager.getResource("blank_icon");
1231        }
1232        return icon;
1233    }
1234
1235    public void hideTreeRelation(FieldItem field) {
1236        field.setAttribute(HIDDEN_TREE_RELATION, Boolean.TRUE);
1237    }
1238
1239    public void setMenu(ClassItem classItem, String[] menu) {
1240        MethodItem[] methods = new MethodItem[menu.length];
1241        for (int i = 0; i < menu.length; i++) {
1242            if (menu[i].equals(""))
1243                methods[i] = null;
1244            else
1245                try {
1246                    methods[i] = classItem.getMethod(menu[i]);
1247                } catch (NoSuchMethodException e) {
1248                    warning(e.toString());
1249                    methods[i] = null;
1250                }
1251        }
1252        classItem.setAttribute(MENU, methods);
1253    }
1254
1255    public static MethodItem[] getMenu(ClassItem classItem) {
1256        Vector methods = new Vector();
1257        while (classItem != null) {
1258            MethodItem[] curmenu = (MethodItem[]) classItem.getAttribute(MENU);
1259            if (curmenu != null) {
1260                for (int i = curmenu.length - 1; i >= 0; i--) {
1261                    if (!methods.contains(curmenu[i]))
1262                        methods.add(0, curmenu[i]);
1263                }
1264            }
1265            classItem = classItem.getSuperclass();
1266        }
1267        MethodItem[] result = new MethodItem[methods.size()];
1268        for (int i = 0; i < result.length; i++) {
1269            result[i] = (MethodItem) methods.get(i);
1270        }
1271        return result;
1272    }
1273
1274    /**
1275     * Catch this event and remove the display from the handled list if
1276     * exists.
1277     *
1278     * @param display the closing display */

1279
1280    public void whenCloseDisplay(Display display) {
1281        removeDisplay(display);
1282    }
1283
1284    public void whenReload() {
1285        Iterator it = displays.values().iterator();
1286        while (it.hasNext()) {
1287            Display display = (Display) it.next();
1288            if (display
1289                .getClass()
1290                .getName()
1291                .equals("org.objectweb.jac.aspects.gui.swing.SwingDisplay")) {
1292                loggerDisplay.debug("Refreshing display " + display);
1293                display.fullRefresh();
1294            }
1295        }
1296    }
1297
1298    public void beforeReload() {
1299        cguis.clear();
1300    }
1301
1302    /**
1303     * The default constructor for the GUI aspect component.
1304     *
1305     * <p>By default it defines the visible property to false for some
1306     * JAC system items.
1307     *
1308     */

1309
1310    public GuiAC() {
1311        blockKeywords = new String[] { "menu", "window", "view" };
1312        setDefaults();
1313    }
1314
1315    /**
1316     * Defines the visible property to false for some JAC system items.
1317     */

1318    public void setDefaults() {
1319        ClassRepository cr = ClassRepository.get();
1320        ClassItem nameRepositoryClass =
1321            cr.getClass("org.objectweb.jac.core.NameRepository");
1322        ClassItem acManagerClass =
1323            cr.getClass("org.objectweb.jac.core.ACManager");
1324        ClassItem topologyClass =
1325            cr.getClass("org.objectweb.jac.core.dist.Topology");
1326
1327        setVisible(nameRepositoryClass.getField("names"), false);
1328        setVisible(
1329            acManagerClass,
1330            new String[] { "registering", "orderedObjects", "orderedNames" },
1331            false);
1332
1333        setVisible(topologyClass.getField("nameReps"), false);
1334        setVisible(
1335            topologyClass.getMember(
1336                "getContainerIndex(org.objectweb.jac.core.dist.RemoteContainer)"),
1337            false);
1338        setVisible(
1339            topologyClass.getMember("getContainerIndex(java.lang.String)"),
1340            false);
1341        setVisible(
1342            topologyClass.getMember("getContainerIndexes(gnu.regexp.RE)"),
1343            false);
1344        setVisible(
1345            topologyClass.getMember("getContainerIndexes(java.lang.String[])"),
1346            false);
1347        setVisible(topologyClass.getMember("countContainers"), false);
1348        setVisible(
1349            topologyClass.getMember("getContainer(java.lang.String)"),
1350            false);
1351        setVisible(topologyClass.getMember("getContainer(int)"), false);
1352        setVisible(topologyClass.getMember("isContainer"), false);
1353        setVisible(topologyClass.getMember("createNameReps"), false);
1354
1355        setTableView(topologyClass.getField("containers"));
1356
1357        setDirectCollectionMethods(
1358            topologyClass.getCollection("containers"),
1359            new String[] { "launchRemoteGUI" });
1360
1361        ClassItem rmiStubClass =
1362            cr.getClass(
1363                "org.objectweb.jac.core.dist.rmi.RMIRemoteContainerStub");
1364        setVisible(rmiStubClass.getMember("copy"), false);
1365        setVisible(rmiStubClass.getMember("getByteCodeFor"), false);
1366        setVisible(rmiStubClass.getMember("instantiates"), false);
1367
1368        ClassItem applicationClass =
1369            cr.getClass("org.objectweb.jac.core.Application");
1370
1371        setVisible(applicationClass.getMember("props"), false);
1372        // applicationClass.setAttribute("GuiAC.List.showItem", applicationClass.getMethod("getName"));
1373
ClassItem applicationManagerClass =
1374            cr.getClass("org.objectweb.jac.core.ApplicationRepository");
1375
1376        setTableMembersOrder(applicationClass,new String[] {"name","constructorClass","instantiated"});
1377
1378        setViewOnSelection(
1379            applicationManagerClass.getCollection("applications"));
1380        setAutoCreate(applicationManagerClass.getField("applications"));
1381
1382        applicationManagerClass.getMethod("addApplication").setAttribute(
1383            ASKING_SEQUENCE,
1384            new Object[] { "autoCreate" });
1385        setVisible(applicationManagerClass.getMember("getApplication"), false);
1386
1387        setCategories(
1388            applicationClass,
1389            new String[] { "Aspects", "Properties" });
1390
1391        setCategory(applicationClass.getMember("name"), "Properties");
1392        setCategory(applicationClass.getMember("path"), "Properties");
1393        setCategory(applicationClass.getMember("instantiated"), "Properties");
1394        setCategory(
1395            applicationClass.getMember("constructorClass"),
1396            "Properties");
1397        setCategory(applicationClass.getMember("arguments"), "Properties");
1398        setCategory(applicationClass.getMember("start"), "Properties");
1399
1400        setCategory(applicationClass.getMember("acs"), "Aspects");
1401        setCategory(applicationClass.getMember("acConfigurations"), "Aspects");
1402
1403        setEmbeddedEditor(applicationClass.getField("name"));
1404        setEmbeddedEditor(applicationClass.getField("path"));
1405
1406        setFileChooserView(
1407            applicationClass.getMethod("setPath"),
1408            new String[] { "" },
1409            "directories");
1410
1411        setViewOnSelection(applicationClass.getCollection("acConfigurations"));
1412        setAutoCreate(applicationClass.getField("acConfigurations"));
1413
1414        //setTableView( "org.objectweb.jac.aspects.distribution.Topology", "containers");
1415

1416        applicationClass.getMethod("addAcConfiguration").setAttribute(
1417            ASKING_SEQUENCE,
1418            new Object[] { "autoCreate" });
1419        //applicationClass.getMethod( "weave" ).setAttribute( CATEGORY, "Aspects");
1420
//applicationClass.getMethod( "unweave" ).setAttribute( CATEGORY, "Aspects");
1421
setCategory(applicationClass.getMember("realizes"), "Aspects");
1422
1423        applicationClass.getMethod("configures").setAttribute(
1424            VISIBLE,
1425            Boolean.FALSE);
1426
1427        applicationClass.getCollection("acs").setAttribute(
1428            VISIBLE,
1429            Boolean.FALSE);
1430
1431        //applicationClass.getCollection( "acs" ).addAddingMethod( applicationClass.getMethod( "weave" ) );
1432
//applicationClass.getCollection( "acs" ).addRemovingMethod( applicationClass.getMethod( "unweave" ) );
1433

1434        setSystemListener(true);
1435
1436        // Trace configuration
1437
/*
1438          generateDefaultParameterNames( "org.objectweb.jac.aspects.gui.WrappableMap" );
1439          setMethodDynamicParameterChoice("org.objectweb.jac.aspects.gui.WrappableMap","put",
1440          new String[] { "org.objectweb.jac.aspects.gui.WrappableMap",
1441          "org.objectweb.jac.aspects.gui.WrappableMap" },
1442          new String[] { "getCategories", "getLevels" },
1443          new String[] { "true", "false"});
1444          setParameterNames("org.objectweb.jac.aspects.gui.WrappableMap","put",
1445          new String[] { "trace", "level"} );
1446          RttiAC rttiac = (RttiAC)ACManager.get().getObject("rtti");
1447          rttiac.addWrittenFields("org.objectweb.jac.aspects.gui.WrappableMap","put",new String[] {"delegate"});
1448        */

1449
1450        pointcut(
1451            "ALL",
1452            "ALL && !org.objectweb.jac.aspects.gui.*Display && !COLLECTIONS",
1453            "MODIFIERS",
1454            ViewControlWrapper.class.getName(),
1455            null,
1456            NOT_SHARED);
1457        //pointcut("ALL","COLLECTIONS","add.* || remove.* || clear.*",
1458
// ViewControlWrapper.class.getName(),"updateView",NOT_SHARED);
1459

1460    }
1461
1462    public void askForParameters(String classExpr) {
1463        // weave InputWrapper.askForParameters on all methods with parameters
1464
pointcut(
1465            "ALL",
1466            classExpr,
1467            "!.*().* && !CONSTRUCTORS",
1468            InputWrapper.class.getName(),
1469            "catchInputCanceled",
1470            SHARED);
1471    }
1472
1473    /**
1474     * The default behavior of this <code>BaseProgramListener</code>
1475     * method is to notify the display with the
1476     * <code>applicationStarted</code> event.
1477     *
1478     * @see org.objectweb.jac.core.Display#applicationStarted() */

1479
1480    public void afterApplicationStarted() {
1481        if (Jac.startSwingGUI()) {
1482            createSwingDisplays(Jac.getStartSwingGUI());
1483        }
1484        if (Jac.startWebGUI()) {
1485            createWebDisplays(Jac.getStartWebGUI());
1486        }
1487    }
1488
1489    /**
1490     * Return a session id for the local display
1491     */

1492    public static String getLocalSessionID() {
1493        return "Swing"
1494            + org.objectweb.jac.core.dist.Distd.getLocalContainerName();
1495    }
1496
1497    /**
1498     * The programmer of a new GUI aspect must overload this method to
1499     * return the right default program name.<p>
1500     *
1501     * By default, it returns the package path name of the current GUI
1502     * aspect (must be right most of the time).
1503     *
1504     * @return the default program name
1505     */

1506
1507    protected String getDefaultProgramName() {
1508        return getClass().getName().substring(
1509            0,
1510            getClass().getName().lastIndexOf('.'));
1511    }
1512
1513    /** A flag to memorize that the mainWindow is beeing launched (or
1514        has already been launched). */

1515    static boolean launched = false;
1516
1517    public void setVisible(MemberItem member, boolean visible) {
1518        logger.debug("setVisible(" + member.getLongName() + "," + visible + ")");
1519        member.setAttribute(VISIBLE, Boolean.valueOf("" + visible));
1520    }
1521
1522    public void setEditable(FieldItem field, boolean editable) {
1523        logger.debug("setEditable(" + field + "," + editable + ")");
1524        if (field != null) {
1525            field.setAttribute(EDITABLE, Boolean.valueOf("" + editable));
1526        }
1527    }
1528
1529    public void setAddable(CollectionItem collection, boolean addable) {
1530        logger.debug("setAddable("+collection+","+addable+")");
1531        collection.setAttribute(ADDABLE, ExtBoolean.valueOf(addable));
1532    }
1533
1534    public void setRemovable(CollectionItem collection, boolean removable)
1535    {
1536        logger.debug("setRemovable("+collection+","+removable+")");
1537        collection.setAttribute(REMOVABLE, ExtBoolean.valueOf(removable));
1538    }
1539
1540    public void setEditableDefaultValues(
1541        CollectionItem collection,
1542        boolean editable) {
1543        collection.setAttribute(
1544            EDITABLE_DEFAULT_VALUES,
1545            editable ? Boolean.TRUE : Boolean.FALSE);
1546    }
1547
1548    public static boolean hasEditableDefaultValues(MetaItem metaItem) {
1549        Object value = metaItem.getAttribute(EDITABLE_DEFAULT_VALUES);
1550        if (value == null)
1551            return false;
1552        else
1553            return ((Boolean) value).booleanValue();
1554    }
1555
1556    /**
1557     * Tells if an item is visible (displayed by the GUI).
1558     *
1559     * @param substance the object holding the meta item
1560     * @param metaItem the meta item to check
1561     * @return true if visible
1562     *
1563     * @see #setVisible(MemberItem,boolean)
1564     * @see #isVisible(Object,MetaItem)
1565     */

1566    public static boolean isVisible(Object substance, MetaItem metaItem) {
1567        Object value = metaItem.getAttribute(substance, VISIBLE);
1568
1569        if (value == null)
1570            return true;
1571        else
1572            return ((Boolean) value).booleanValue();
1573    }
1574
1575    /**
1576     * Tells if an item is visible (displayed by the GUI).
1577     *
1578     * @param metaItem the meta item to check
1579     * @return true if visible
1580     *
1581     * @see #setVisible(MemberItem,boolean)
1582     * @see #isVisible(MetaItem)
1583     */

1584    public static boolean isVisible(MetaItem metaItem) {
1585        Object value = metaItem.getAttribute(VISIBLE);
1586
1587        if (value == null)
1588            return true;
1589        else
1590            return ((Boolean) value).booleanValue();
1591    }
1592
1593    /**
1594     * Tells if a field is editable from the GUI.
1595     *
1596     * @param substance the object holding the field item
1597     * @param field the field item to check
1598     * @return true if the field is editable
1599     */

1600    public static boolean isEditable(Object substance, FieldItem field) {
1601        Object value = field.getAttribute(substance, EDITABLE);
1602        return field.getSetter() != null
1603            && (value == null || ((Boolean) value).booleanValue());
1604    }
1605
1606    /**
1607     * Tells if a field is editable from the GUI.
1608     *
1609     * @param field the field item to check
1610     * @return true if the field is editable
1611     */

1612    public static boolean isEditable(FieldItem field) {
1613        Object value = field.getAttribute(EDITABLE);
1614        return field.getSetter() != null
1615            && (value == null || ((Boolean) value).booleanValue());
1616    }
1617
1618    /**
1619     * Wether to show "new" buttons for a class (defaults to true)
1620     * @param cli the class
1621     */

1622    public static boolean isCreatable(ClassItem cli) {
1623        Object value = cli.getAttribute(CREATABLE);
1624        return value == null || ((Boolean) value).booleanValue();
1625    }
1626
1627    /**
1628     * Tells wether to show an add button for a collection
1629     *
1630     * @param collection the collection item to check
1631     * @return true if an add button must be displayed
1632     */

1633    public static boolean isAddable(CollectionItem collection) {
1634        Object value = collection.getAttribute(ADDABLE);
1635        MethodItem adder = collection.getAdder();
1636        return adder != null
1637            && isVisible(adder)
1638            && (value == null || ((Boolean) value).booleanValue());
1639    }
1640
1641    /**
1642     * Tells wether to show an add button for a collection
1643     *
1644     * @param substance the object holding the field item
1645     * @param collection the collection item to check
1646     * @return true if an add button must be displayed
1647     */

1648    public static boolean isAddable(
1649        Object substance,
1650        CollectionItem collection)
1651    {
1652        Object value = collection.getAttribute(substance, ADDABLE);
1653        MethodItem adder = collection.getAdder();
1654        return adder != null
1655            && isVisible(substance, adder)
1656            && (value == null || ((Boolean) value).booleanValue());
1657    }
1658
1659    /**
1660     * Tells wether to show a remove button for a collection
1661     *
1662     * @param collection the collection item to check
1663     * @return true if a remove button must be displayed
1664     */

1665    public static boolean isRemovable(CollectionItem collection) {
1666        Object value = collection.getAttribute(REMOVABLE);
1667        MethodItem remover = collection.getRemover();
1668        return remover != null
1669            && isVisible(remover)
1670            && (value == null || ((Boolean) value).booleanValue());
1671    }
1672
1673    /**
1674     * Tells wether to show a remove button for a collection
1675     *
1676     * @param substance the object holding the field item
1677     * @param collection the collection item to check
1678     * @return true if a remove button must be displayed
1679     */

1680    public static boolean isRemovable(
1681        Object substance,
1682        CollectionItem collection)
1683    {
1684        Object value = collection.getAttribute(substance, REMOVABLE);
1685        MethodItem remover = collection.getRemover();
1686        return remover != null
1687            && isVisible(remover)
1688            && (value == null || ((Boolean) value).booleanValue());
1689    }
1690
1691    public void setVisible(ClassItem cl, String itemNames[], boolean visible) {
1692        for (int i = 0; i < itemNames.length; i++) {
1693            setVisible(cl.getMember(itemNames[i]), visible);
1694        }
1695    }
1696
1697    public void setReadOnly(ClassItem cli, String viewName, boolean readOnly) {
1698        getView(cli,viewName).setReadOnly(readOnly);
1699    }
1700
1701    public void setEmbeddedEditors(ClassItem cli) {
1702        setEmbeddedEditors(cli,DEFAULT_VIEW,true);
1703    }
1704
1705    public void setEmbeddedEditors(ClassItem cli, String viewName, boolean embedded) {
1706        FieldItem[] fields = cli.getFields();
1707        if (fields != null) {
1708            for (int i = 0; i < fields.length; i++) {
1709                setEmbeddedEditor(fields[i],viewName,embedded);
1710            }
1711        }
1712    }
1713
1714    public void setEmbeddedEditor(MemberItem member) {
1715        setEmbeddedEditor(member,DEFAULT_VIEW,true);
1716    }
1717
1718    public void setEmbeddedEditor(MemberItem member, String viewName, boolean embedded) {
1719        if (member instanceof FieldItem) {
1720            FieldItem field = (FieldItem) member;
1721            if (!(field instanceof CollectionItem)) {
1722                if (field.getSetter() == null) {
1723                    //Log.warning("setEmbeddedEditor: no setter for "+cl+"."+itemName+", ignored");
1724
} else {
1725                    getView(field,viewName).setEmbeddedEditor(embedded);
1726                }
1727            }
1728            return;
1729        } else {
1730            getView(member,viewName).setEmbeddedEditor(embedded);
1731            //member.setAttribute(EMBEDDED_EDITOR, Boolean.TRUE);
1732
}
1733    }
1734
1735    public void setEmbeddedEditors(
1736        CollectionItem collection,
1737        String viewName,
1738        boolean embedded)
1739    {
1740        CollectionItemView itemView =
1741            (CollectionItemView) getView(collection, viewName);
1742        itemView.setEmbeddedEditors(embedded);
1743        loggerTable.debug("setEmbeddedEditors "+collection+"/"+viewName+"/"+embedded+
1744                          "->"+itemView);
1745    }
1746
1747    public void setEmbeddedEditorColumns(
1748        CollectionItem collection,
1749        String viewName,
1750        MemberItem[] members)
1751    {
1752        CollectionItemView itemView =
1753            (CollectionItemView) getView(collection, viewName);
1754        for (int i = 0; i < members.length; i++) {
1755            itemView.addEmbeddedEditorColumn(members[i]);
1756        }
1757    }
1758
1759    public void setMultiLineCollection(
1760        CollectionItem collection,
1761        String viewName,
1762        CollectionItem multiLine)
1763    {
1764        CollectionItemView itemView =
1765            (CollectionItemView) getView(collection, viewName);
1766        itemView.setMultiLineCollection(multiLine);
1767    }
1768
1769    public void setAdditionalRow(CollectionItem collection,
1770                                 String viewName,
1771                                 String row) {
1772        CollectionItemView itemView =
1773            (CollectionItemView) getView(collection, viewName);
1774        itemView.setAdditionalRow(collection.getClassItem().getField(row));
1775    }
1776
1777    public void groupBy(
1778        CollectionItem collection,
1779        String viewName,
1780        FieldItem groupBy)
1781    {
1782        CollectionItemView itemView =
1783            (CollectionItemView) getView(collection, viewName);
1784        itemView.setGroupBy(groupBy);
1785    }
1786
1787    public void setViewType(
1788        FieldItem field,
1789        String viewName,
1790        String viewType)
1791    {
1792        MemberItemView itemView = (MemberItemView) getView(field, viewName);
1793        itemView.setViewType(viewType);
1794    }
1795
1796    /**
1797     * @return true is the item has the property Gui.embeddedEditor set
1798     * to "true"
1799     * @see #hasEmbeddedEditors(ClassItem)
1800     * @see #setEmbeddedEditor(MemberItem)
1801     */

1802    public static boolean isEmbeddedEditor(MetaItem item) {
1803        Boolean value = (Boolean) item.getAttribute(EMBEDDED_EDITOR);
1804        return value != null && value.booleanValue();
1805    }
1806
1807    /**
1808     * Returns the value of the EMBEDDED_EDITORS atrribute from the
1809     * current collaboration. Defaults to false.
1810     */

1811    /*
1812      public static boolean isEmbeddedEditors() {
1813      Boolean value =
1814      (Boolean) Collaboration.get().getAttribute(GuiAC.EMBEDDED_EDITORS);
1815      return value != null && value.booleanValue();
1816      }
1817    */

1818
1819    /**
1820     * @return true if at least one field of the class has the property
1821     * Gui.embeddedEditor set to "true"
1822     * @see #isEmbeddedEditor(MetaItem)
1823     * @see #setEmbeddedEditor(MemberItem)
1824     */

1825    public static boolean hasEmbeddedEditors(ClassItem cli) {
1826        FieldItem fields[] = cli.getFields();
1827        String[] cats = (String[]) cli.getAttribute(CATEGORIES);
1828        if (fields != null) {
1829            for (int i = 0; i < fields.length; i++) {
1830                if (fields[i] instanceof CollectionItem)
1831                    continue;
1832                if (cats != null && fields[i].getAttribute(CATEGORIES) == null)
1833                    continue;
1834                                //(Arrays.asList(cats).contains(fields[i].getAttribute(CATEGORY)))
1835
// continue;
1836
if (isEmbeddedEditor(fields[i]) && isVisible(fields[i])) {
1837                    return true;
1838                }
1839            }
1840        }
1841        return false;
1842    }
1843
1844    //public void setBorder(ClassItem cli, String fieldName,
1845
public void setBorder(FieldItem field, String alignment, String style) {
1846        //FieldItem field = cli.getField(fieldName);
1847
field.setAttribute(
1848            BORDER,
1849            new Border(
1850                null,
1851                Border.a2iAlignment(alignment),
1852                Border.a2iStyle(style)));
1853    }
1854
1855    //public void setBorder(ClassItem cli, String fieldName) {
1856
public void setBorder(FieldItem field) {
1857        setBorder(field, "LEFT", "LINE");
1858    }
1859
1860    public static Border getBorder(FieldItem field) {
1861        return (Border) field.getAttribute(BORDER);
1862    }
1863
1864    public void setCondition(AbstractMethodItem method, String condition) {
1865        ClassItem cl = method.getClassItem();
1866        MethodItem cond = cl.getMethod(condition);
1867        method.setAttribute(CONDITION, cond);
1868    }
1869
1870    /**
1871     * Gets the condition method associated with a method, or null if
1872     * there's none.
1873     */

1874    public static MethodItem getCondition(AbstractMethodItem method) {
1875        return (MethodItem) method.getAttribute(CONDITION);
1876    }
1877
1878    public void setSlowOperation(AbstractMethodItem method, boolean isSlow) {
1879        method.setAttribute(SLOW_OPERATION,ExtBoolean.valueOf(isSlow));
1880        if (isSlow) {
1881            pointcut(
1882                "ALL",
1883                method.getClassItem().getName(),
1884                method.toString(),
1885                WaitWrapper.class.getName(),
1886                null,SHARED);
1887        }
1888    }
1889    
1890    public void setMimeType(AbstractMethodItem method, String type) {
1891        method.setAttribute(MIME_TYPE,type);
1892    }
1893
1894    /**
1895     * Tells wethers a method is slow
1896     */

1897    public static boolean isSlowOperation(AbstractMethodItem method) {
1898        return method.getBoolean(SLOW_OPERATION,false);
1899    }
1900
1901    public void addPostInvoke(AbstractMethodItem method,
1902                              AbstractMethodItem hook) {
1903        List hooks = (List)method.getAttribute(POST_INVOKE_HOOKS);
1904        if (hooks==null) {
1905            hooks = new Vector();
1906            method.setAttribute(POST_INVOKE_HOOKS,hooks);
1907        }
1908        hooks.add(hook);
1909    }
1910
1911
1912    /**
1913     * Tells wether a method should be enabled
1914     */

1915    public static boolean isEnabled(
1916        AbstractMethodItem method,
1917        Object substance)
1918    {
1919        MethodItem condition = (MethodItem) method.getAttribute(CONDITION);
1920        if (condition != null) {
1921            loggerMenu.debug("Condition for " + method.getFullName() + ": " + condition);
1922            return ((Boolean) condition.invoke(substance, ExtArrays.emptyObjectArray))
1923                .booleanValue();
1924        } else {
1925            loggerMenu.debug("No condition for " + method.getFullName());
1926            return true;
1927        }
1928    }
1929
1930    public void setMethodParametersWidth(AbstractMethodItem method,
1931                                         Length[] width)
1932        throws Exception
1933    {
1934        if (method.getParameterCount() != Array.getLength(width)) {
1935            throw new Exception(
1936                "setMethodParametersWidth: wrong number of parameters widths for "
1937                + method.getName());
1938        }
1939        method.setAttribute(EDITOR_WIDTH, width);
1940    }
1941
1942    /**
1943     * Returns the parameters widths of a method or null if none was set.
1944     * @param method the method
1945     * @see #setMethodParametersWidth(AbstractMethodItem,Length[])
1946     */

1947    public static Length[] getMethodParametersWidth(AbstractMethodItem method) {
1948        return (Length[]) method.getAttribute(EDITOR_WIDTH);
1949    }
1950
1951    public void setMethodParametersHeight(AbstractMethodItem method,
1952                                          Length[] height)
1953        throws Exception
1954    {
1955        if (method.getParameterCount() != Array.getLength(height)) {
1956            throw new Exception(
1957                "setMethodParametersHeight: wrong number of parameters heights for "
1958                + method.getName());
1959        }
1960        method.setAttribute(EDITOR_HEIGHT, height);
1961    }
1962
1963    /**
1964     * Returns the parameters heights of a method or null if none was set.
1965     * @param method the method
1966     * @see #setMethodParametersHeight(AbstractMethodItem,Length[])
1967     */

1968    public static Length[] getMethodParametersHeight(AbstractMethodItem method) {
1969        return (Length[]) method.getAttribute(EDITOR_HEIGHT);
1970    }
1971
1972    public void setDefaultEditorWidth(VirtualClassItem type,
1973                                      Length width)
1974    {
1975        type.setAttribute(EDITOR_WIDTH, width);
1976    }
1977
1978    public void setDefaultEditorWidth(ClassItem type, Length width) {
1979        type.setAttribute(EDITOR_WIDTH, width);
1980    }
1981
1982    public static Length getEditorWidth(MetaItem type) {
1983        return (Length)type.getAttribute(EDITOR_WIDTH);
1984    }
1985
1986    public static Length getEditorHeight(MetaItem type) {
1987        return (Length)type.getAttribute(EDITOR_HEIGHT);
1988    }
1989
1990    public void setEditorWidth(FieldItem field, Length width) {
1991        field.setAttribute(EDITOR_WIDTH, width);
1992    }
1993
1994    /**
1995     * Returns the editor width of a field or 0 if none was set.
1996     * @param field the field
1997     * @see #setEditorWidth(FieldItem,Length)
1998     */

1999    public static Length getEditorWidth(FieldItem field) {
2000        return (Length)field.getAttribute(EDITOR_WIDTH);
2001    }
2002
2003    public void setSmallEditorWidth(FieldItem field, Length width) {
2004        field.setAttribute(EDITOR_SMALL_WIDTH, width);
2005    }
2006
2007    public void setDefaultEditorHeight(VirtualClassItem type, Length height)
2008    {
2009        type.setAttribute(EDITOR_HEIGHT, height);
2010    }
2011
2012    public void setDefaultEditorHeight(ClassItem type, Length height) {
2013        type.setAttribute(EDITOR_HEIGHT, height);
2014    }
2015
2016    public void setEditorHeight(FieldItem field, Length height) {
2017        field.setAttribute(EDITOR_HEIGHT, height);
2018    }
2019
2020    public void setSmallEditorHeight(FieldItem field, Length height) {
2021        field.setAttribute(EDITOR_SMALL_HEIGHT, height);
2022    }
2023
2024    static Map fontAttributes = new HashMap();
2025
2026    public void setFontAttribute(String attribute, String value) {
2027        fontAttributes.put(attribute.toLowerCase(), value);
2028    }
2029
2030    public static Map getFontAttributes() {
2031        return fontAttributes;
2032    }
2033
2034    public void setCategories(ClassItem cli, String[] categories) {
2035        cli.setAttribute(CATEGORIES, categories);
2036    }
2037
2038    /*
2039      public void setCategories(ClassItem cli, String viewName,
2040      String[] categories) {
2041      getView(cli,viewName).setCategories(categories);
2042      }
2043    */

2044
2045    public void setCategory(MemberItem member, String category) {
2046        setCategories(member, new String[] { category });
2047    }
2048
2049    public void setCategories(MemberItem member, String[] categories) {
2050        member.setAttribute(CATEGORIES, categories);
2051    }
2052
2053    /**
2054     * Get the category of a member as configured with setCategory().
2055     *
2056     * @param member the MemberItem
2057     * @return the category of the field or null.
2058     */

2059    public static String[] getCategories(MemberItem member) {
2060        return (String[]) member.getAttribute(CATEGORIES);
2061    }
2062
2063    /**
2064     * Tells wether a member item belong to category
2065     * @return if category==null, true, otherwise if the categories of
2066     * the member contains the category, true, otherwise false.
2067     * @see #setCategory(MemberItem,String)
2068     * @see #setCategories(MemberItem,String[])
2069     */

2070    public static boolean isMemberInCategory(
2071        MemberItem member,
2072        String category) {
2073        if (category == null) {
2074            return true;
2075        }
2076
2077        String[] categories = getCategories(member);
2078        if (categories == null)
2079            return false;
2080        for (int i = 0; i < categories.length; i++) {
2081            if (categories[i].equals(category)) {
2082                return true;
2083            }
2084        }
2085        return false;
2086    }
2087
2088    public void checkCategories(ClassItem cli, int length) {
2089        //String[] categories = getView(cli,DEFAULT_VIEW).getCategories();
2090
String[] categories = (String[]) cli.getAttribute(CATEGORIES);
2091        if (categories == null || categories.length != length) {
2092            throw new RuntimeException(
2093                "Wrong number of icons for categories of class " + cli);
2094        }
2095    }
2096
2097    public void setCategoriesIcons(ClassItem cli, String[] icons) {
2098        // checkCategories(cli,icons.length);
2099
for (int i = 0; i < Array.getLength(icons); i++) {
2100            String str = ResourceManager.getResource(icons[i]);
2101            if (str == null)
2102                warning("setCategoriesIcons: icon not found " + icons[i]);
2103            icons[i] = str;
2104        }
2105
2106        cli.setAttribute(CATEGORIES_ICONS, icons);
2107    }
2108
2109    /**
2110     * Get the categories icons (icons displayed in tabs).
2111     *
2112     * @param cl the class.
2113     * @return the list of icons.
2114     */

2115    public static String[] getCategoriesIcons(ClassItem cl) {
2116        return (String[]) cl.getAttribute(CATEGORIES_ICONS);
2117    }
2118
2119    public void setCategoriesLabels(ClassItem cli, String[] labels) {
2120        // checkCategories(cli,labels.length);
2121
cli.setAttribute(CATEGORIES_LABELS, labels);
2122    }
2123
2124    /**
2125     * Get the categories labels (text displayed in tabs).
2126     *
2127     * @param cl the class
2128     * @return the list of labels.
2129     */

2130    public static String[] getCategoriesLabels(ClassItem cl) {
2131        return (String[]) cl.getAttribute(CATEGORIES_LABELS);
2132    }
2133
2134    public void setEmbeddedView(MemberItem member) {
2135        setEmbeddedView(member, GuiAC.DEFAULT_VIEW, true);
2136    }
2137
2138    public void setEmbeddedView(MemberItem member, boolean embedded) {
2139        setEmbeddedView(member, GuiAC.DEFAULT_VIEW, embedded);
2140    }
2141
2142    public void setEmbeddedView(
2143        MemberItem member,
2144        String viewName,
2145        boolean embedded)
2146    {
2147        getView(member, viewName).setEmbedded(embedded);
2148    }
2149
2150    public void setEmbeddedAdder(CollectionItem collection, boolean embedded) {
2151        setEmbeddedView(collection.getAdder(), embedded);
2152    }
2153
2154    /**
2155     * Tells if a field item's value must be displayed embbeded.
2156     * @return wether to display the field's values embbeded, default
2157     * to false.
2158     */

2159    /*
2160      public static boolean isEmbbededView(MemberItem member) {
2161      Boolean value = (Boolean)member.getAttribute(EMBEDDED_VIEW);
2162      return value!=null && value.booleanValue();
2163      }
2164    */

2165
2166    public void setDesktopCustomizedView(ClassItem classItem, ClassItem type) {
2167        classItem.setAttribute(DESKTOP_VIEW, type);
2168    }
2169
2170    public void setTableView(FieldItem field) {
2171        field.setAttribute(TABLE_VIEW, Boolean.TRUE);
2172    }
2173
2174    public void setChoiceView(CollectionItem field, boolean external) {
2175        field.setAttribute(CHOICE_VIEW, ExtBoolean.valueOf(external));
2176    }
2177
2178    public void showRowNumbers(CollectionItem collection, boolean value) {
2179        collection.setAttribute(
2180            SHOW_ROW_NUMBERS,
2181            value ? Boolean.TRUE : Boolean.FALSE);
2182    }
2183
2184    protected static boolean defaultShowRowNumbers = false;
2185
2186    public void setDefaultShowRowNumbers(boolean value) {
2187        defaultShowRowNumbers = value;
2188    }
2189
2190    public static boolean isShowRowNumbers(CollectionItem collection) {
2191        return collection.getBoolean(SHOW_ROW_NUMBERS, defaultShowRowNumbers);
2192    }
2193
2194    public void setToString(ClassItem classItem, String formatExpression) {
2195        classItem.setAttribute(TO_STRING, formatExpression);
2196    }
2197
2198    public void setToString(
2199        ClassItem classItem,
2200        MemberItem selector,
2201        String formatExpression)
2202    {
2203        Map rules = (Map) classItem.getAttributeAlways(CONTEXTUAL_TO_STRING);
2204        if (rules == null) {
2205            rules = new HashMap();
2206            classItem.setAttribute(CONTEXTUAL_TO_STRING, rules);
2207        }
2208        rules.put(selector, formatExpression);
2209    }
2210
2211    public void setToString(
2212        ClassItem classItem,
2213        ClassItem selector,
2214        String formatExpression)
2215    {
2216        Map rules = (Map) classItem.getAttributeAlways(CONTEXTUAL_TO_STRING);
2217        if (rules == null) {
2218            rules = new HashMap();
2219            classItem.setAttribute(CONTEXTUAL_TO_STRING, rules);
2220        }
2221        rules.put(selector, formatExpression);
2222    }
2223
2224    public void setToolTipText(ClassItem classItem, String formatExpression) {
2225        classItem.setAttribute(TOOLTIP, formatExpression);
2226    }
2227
2228    public void setToolTipText(
2229        ClassItem classItem,
2230        MemberItem selector,
2231        String formatExpression)
2232    {
2233        Map rules = (Map) classItem.getAttributeAlways(CONTEXTUAL_TOOLTIP);
2234        if (rules == null) {
2235            rules = new HashMap();
2236            classItem.setAttribute(CONTEXTUAL_TOOLTIP, rules);
2237        }
2238        rules.put(selector, formatExpression);
2239    }
2240
2241    public void setToolTipText(
2242        ClassItem classItem,
2243        ClassItem selector,
2244        String formatExpression)
2245    {
2246        Map rules = (Map) classItem.getAttributeAlways(CONTEXTUAL_TOOLTIP);
2247        if (rules == null) {
2248            rules = new HashMap();
2249            classItem.setAttribute(CONTEXTUAL_TOOLTIP, rules);
2250        }
2251        rules.put(selector, formatExpression);
2252    }
2253
2254    public void showColumnFilters(CollectionItem collection,
2255                                  String[] columnNames) {
2256        ClassItem type = collection.getComponentType();
2257        Vector columns = new Vector();
2258        for (int i=0; i< columnNames.length; i++) {
2259            FieldItem field = type.getFieldNoError(columnNames[i]);
2260            if (field!=null) {
2261                columns.add(field);
2262            } else {
2263                warning("gui.showColumnFilters: no such field "+columnNames[i]+" in "+type.getName());
2264            }
2265        }
2266        collection.setAttribute(FILTERED_COLUMNS,columns);
2267    }
2268
2269    public void setDefaultSortedColumn(
2270        CollectionItem collection,
2271        String column)
2272    {
2273        collection.setAttribute(DEF_SORT, column);
2274    }
2275
2276    public void setDefaultSortedColumn(ClassItem cl, String column) {
2277        cl.setAttribute(DEF_SORT, column);
2278    }
2279
2280    public static String getDefaultSortedColumn(CollectionItem collection) {
2281        String column = (String) collection.getAttribute(GuiAC.DEF_SORT);
2282        if (column == null) {
2283            ClassItem type = collection.getComponentType();
2284            if (type != null)
2285                column = (String) type.getAttribute(GuiAC.DEF_SORT);
2286        }
2287        return column;
2288    }
2289
2290    public void setAutoCreate(FieldItem field) {
2291        field.setAttribute(AUTO_CREATE, Boolean.TRUE);
2292    }
2293
2294    public static boolean isAutoCreate(FieldItem field) {
2295        Boolean bool = (Boolean) field.getAttribute(AUTO_CREATE);
2296        if (bool != null)
2297            return bool.booleanValue();
2298        else if (field instanceof CollectionItem) {
2299            CollectionItem collection = (CollectionItem) field;
2300            MethodItem adder = collection.getAdder();
2301            if (adder != null)
2302                return GuiAC.isAutoCreateParameters(adder);
2303        } else {
2304            MethodItem setter = field.getSetter();
2305            if (setter != null)
2306                return GuiAC.isAutoCreateParameters(setter);
2307        }
2308        return false;
2309    }
2310
2311    public void setAutoCreateInitializer(
2312        FieldItem field,
2313        MethodItem initializer)
2314    {
2315        field.setAttribute(AUTO_CREATE_INITIALIZER, initializer);
2316    }
2317
2318    /**
2319     * Returns the initializer method of a field, if any, or null.
2320     * @param field the field
2321     * @see #setAutoCreateInitializer(FieldItem,MethodItem)
2322     */

2323    public static MethodItem getInitiliazer(FieldItem field) {
2324        return (MethodItem) field.getAttribute(AUTO_CREATE_INITIALIZER);
2325    }
2326
2327    public void setAutoCreateParameters(AbstractMethodItem method) {
2328        method.setAttribute(AUTO_CREATE, Boolean.TRUE);
2329    }
2330
2331    public static boolean isAutoCreateParameters(AbstractMethodItem method) {
2332        return method.getBoolean(AUTO_CREATE, false);
2333    }
2334
2335    public void setAutoCreateAll(ClassItem cl) {
2336        setAutoCreateParametersEx(cl, ExtArrays.emptyStringArray);
2337    }
2338
2339    public void setAutoCreateParametersEx(
2340        ClassItem cli,
2341        String[] excludedMethods)
2342    {
2343        Class clazz = cli.getActualClass();
2344        boolean error = false;
2345        try {
2346            Iterator it = cli.getAllMethods().iterator();
2347            List l = Arrays.asList(excludedMethods);
2348            while (it.hasNext()) {
2349                MethodItem cur = (MethodItem) it.next();
2350                if ((!l.contains(cur.getName()))
2351                    && (!cur.isRemover())
2352                    && cur.getActualMethod().getDeclaringClass() == clazz) {
2353                    try {
2354                        setAutoCreateParameters(cur);
2355                    } catch (Exception e) {
2356                        e.printStackTrace();
2357                    }
2358                }
2359            }
2360        } catch (Exception e) {
2361            e.printStackTrace();
2362        }
2363    }
2364
2365    public void setAutoCreateState(ClassItem cli, String[] fields) {
2366        cli.setAttribute(AUTO_CREATED_STATE, fields);
2367    }
2368
2369    public void setOpenViewMethod(ClassItem cli, String methodName) {
2370        MetaItem mi = cli.getMethod(methodName);
2371        mi.setAttribute(OPEN_VIEW, Boolean.TRUE);
2372    }
2373
2374    public void declareView(
2375        ClassItem cli,
2376        String viewName,
2377        String parentViewName)
2378    {
2379        ObjectView view =
2380            new ObjectView(cli, viewName, getView(cli, parentViewName));
2381        Map views = (Map) cli.getAttributeAlways(VIEWS);
2382        if (views == null) {
2383            views = new HashMap();
2384            cli.setAttribute(VIEWS, views);
2385        }
2386        views.put(viewName, view);
2387    }
2388
2389    public void declareView(ClassItem cli, String viewName) {
2390        declareView(cli, viewName, DEFAULT_VIEW);
2391    }
2392
2393    /**
2394     * Gets an object view by name. Creates one if it does not exist
2395     */

2396    public static ObjectView getView(ClassItem cli, String viewName) {
2397        Map views = (Map) cli.getAttributeAlways(VIEWS);
2398        if (views == null) {
2399            views = new HashMap();
2400            cli.setAttribute(VIEWS, views);
2401        }
2402        ObjectView view = (ObjectView) views.get(viewName);
2403        if (view == null) {
2404            if (viewName.equals(DEFAULT_VIEW))
2405                view = new ObjectView(cli, viewName);
2406            else
2407                view = new ObjectView(cli, viewName, getView(cli,DEFAULT_VIEW));
2408        }
2409        views.put(viewName, view);
2410        return view;
2411    }
2412
2413    /**
2414     * Gets an object view by name. Creates one if it does not exist
2415     */

2416    public static MemberItemView getView(MemberItem member, String viewName) {
2417        Map views = (Map) member.getAttributeAlways(VIEWS);
2418        if (views == null) {
2419            views = new HashMap();
2420            member.setAttribute(VIEWS, views);
2421        }
2422        MemberItemView view = (MemberItemView) views.get(viewName);
2423        if (view == null) {
2424            if (member instanceof CollectionItem)
2425                view =
2426                    new CollectionItemView((CollectionItem) member, viewName);
2427            else if (member instanceof FieldItem)
2428                view = new FieldItemView((FieldItem) member, viewName);
2429            else if (member instanceof MethodItem)
2430                view = new MethodItemView((MethodItem) member, viewName);
2431        }
2432        views.put(viewName, view);
2433        return view;
2434    }
2435
2436    /**
2437     * Gets an object view by name. Creates one if it does not exist
2438     */

2439    public static CollectionItemView getView(
2440        CollectionItem collection,
2441        String viewName)
2442    {
2443        Map views = (Map) collection.getAttributeAlways(VIEWS);
2444        if (views == null) {
2445            views = new HashMap();
2446            collection.setAttribute(VIEWS, views);
2447        }
2448        CollectionItemView view = (CollectionItemView) views.get(viewName);
2449        if (view == null) {
2450            view = new CollectionItemView(collection, viewName);
2451        }
2452        views.put(viewName, view);
2453        return view;
2454    }
2455
2456    public void setAttributesOrder(ClassItem cli, String[] attributeNames) {
2457        setAttributesOrder(cli, DEFAULT_VIEW, attributeNames);
2458    }
2459
2460    public void setAttributesOrder(
2461        ClassItem cli,
2462        String viewName,
2463        String[] attributeNames)
2464    {
2465        getView(cli, viewName).setAttributesOrder(
2466            cli.getFields(attributeNames));
2467    }
2468
2469    public void setLineBreaks(ClassItem cli, String[] fields) {
2470        FieldItem[] lineBreaks = new FieldItem[fields.length];
2471        for (int i = 0; i < fields.length; i++) {
2472            lineBreaks[i] = cli.getField(fields[i]);
2473        }
2474        cli.setAttribute(LINE_BREAKS, lineBreaks);
2475    }
2476
2477    public void setMethodsOrder(ClassItem cli, String[] methodNames) {
2478        setMethodsOrder(cli, DEFAULT_VIEW, methodNames);
2479    }
2480
2481    public void setMethodsOrder(
2482        ClassItem cli,
2483        String viewName,
2484        String[] methodNames)
2485    {
2486        getView(cli, viewName).setMethodsOrder(cli.getMethods(methodNames));
2487    }
2488
2489    public void setCreationAttributesOrder(
2490        ClassItem cli,
2491        String[] attributeNames)
2492    {
2493        setAttributesOrder(cli, AUTOCREATE_VIEW, attributeNames);
2494    }
2495
2496    /**
2497     * Gets the field items to display when creation a new instance a class
2498     */

2499    public static FieldItem[] getCreationAttributesOrder(ClassItem cl) {
2500        FieldItem[] fields = getView(cl,AUTOCREATE_VIEW).getAttributesOrder();
2501        if (fields == null) {
2502            fields = getView(cl,DEFAULT_VIEW).getAttributesOrder();
2503            if (fields == null) {
2504                fields = cl.getFields();
2505            }
2506        }
2507        return fields;
2508    }
2509
2510    public static boolean isCreationAttribute(FieldItem field) {
2511        ClassItem cl = field.getClassItem();
2512        FieldItem[] attributesOrder = getCreationAttributesOrder(cl);
2513        if (attributesOrder == null)
2514            return true;
2515        return ExtArrays.contains(attributesOrder, field);
2516    }
2517
2518    public void setMembersOrder(
2519        CollectionItem collection,
2520        ClassItem targetClass,
2521        String[] memberNames)
2522    {
2523        setMembersOrder(collection, DEFAULT_VIEW, targetClass, memberNames);
2524    }
2525
2526    public void setMembersOrder(
2527        CollectionItem collection,
2528        String viewName,
2529        ClassItem targetClass,
2530        String[] memberNames)
2531    {
2532        CollectionItemView itemView = getView(collection,viewName);
2533        itemView.setMembersOrder(targetClass.getMembers(memberNames));
2534    }
2535
2536    public static MemberItem[] getMembersOrder(
2537        CollectionItem collection,
2538        String viewName)
2539    {
2540        CollectionItemView itemView = getView(collection,viewName);
2541        return itemView.getMembersOrder();
2542    }
2543
2544    public void setTableMembersOrder(ClassItem cli, String[] memberNames) {
2545        setTableMembersOrder(cli,DEFAULT_VIEW,memberNames);
2546    }
2547
2548    public void setTableMembersOrder(ClassItem cli, String viewName,
2549                                     String[] memberNames) {
2550        ObjectView view = getView(cli,viewName);
2551        view.setTableMembersOrder(cli.getMembers(memberNames));
2552    }
2553
2554    public void setTreeAttributesOrder(
2555        ClassItem cli,
2556        String[] attributeNames)
2557    {
2558        cli.setAttribute(TREE_ATTRIBUTES_ORDER, cli.getFields(attributeNames));
2559    }
2560
2561    public void setFieldChoice(
2562        FieldItem field,
2563        Boolean editable,
2564        String[] choice)
2565    {
2566        Object[] choice2 = choice;
2567        choice2 = new Object[choice.length];
2568        try {
2569            logger.debug("setFieldChoice " + field.getType());
2570            for (int i = 0; i < choice.length; i++) {
2571                choice2[i] =
2572                    ClassRepository.instantiate(field.getType(), choice[i]);
2573            }
2574        } catch (Exception e) {
2575            e.printStackTrace();
2576        }
2577        field.setAttribute(FIELD_CHOICE, choice2);
2578        field.setAttribute(EDITABLE_CHOICE, editable);
2579    }
2580
2581    public void setFieldEnum(FieldItem field, String enumName) {
2582        Enum enum = (Enum) enums.get(enumName);
2583        if (enum == null) {
2584            throw new RuntimeException("Unknown enumeration: " + enumName);
2585        }
2586        field.setAttribute(FIELD_ENUM, enum);
2587    }
2588
2589    public static Enum getEnum(FieldItem field) {
2590        return (Enum)field.getAttribute(FIELD_ENUM);
2591    }
2592
2593    public void setParameterEnums(
2594        AbstractMethodItem method,
2595        String[] enumNames)
2596        throws Exception
2597    {
2598        if (enumNames.length != method.getParameterCount())
2599            throw new Exception(
2600                method.getName()
2601                + " expects "
2602                + method.getParameterCount()
2603                + " parameters");
2604        Enum[] enums = new Enum[enumNames.length];
2605        for (int i = 0; i < enumNames.length; i++) {
2606            if (enumNames[i] != null) {
2607                enums[i] = (Enum) this.enums.get(enumNames[i]);
2608                if (enums[i] == null) {
2609                    warning(
2610                        "setParameterEnums(" + method.getName()
2611                        + "): Unknown enumeration: " + enumNames[i]);
2612                }
2613            }
2614        }
2615        method.setAttribute(PARAMETER_ENUMS, enums);
2616    }
2617
2618    public void setLinkedParameters(
2619        AbstractMethodItem method,
2620        String[] collections)
2621        throws Exception
2622    {
2623        if (collections.length != method.getParameterCount())
2624            throw new Exception(
2625                method.getName()
2626                + " expects "
2627                + method.getParameterCount()
2628                + " parameters");
2629        CollectionItem[] colls = new CollectionItem[collections.length];
2630        for (int i = 0; i < collections.length; i++) {
2631            if (!collections[i].equals("")) {
2632                colls[i] =
2633                    (CollectionItem) MemberItem.getMemberFromFullName(
2634                        collections[i]);
2635            } else {
2636                colls[i] = null;
2637            }
2638        }
2639        method.setAttribute(LINKED_PARAMETERS, colls);
2640    }
2641
2642    public void setDefaultValue(
2643        FieldItem field,
2644        MethodItem method,
2645        String value)
2646    {
2647        field.setAttribute(DYN_DEFAULT_VALUE, new Object[] { method, value });
2648    }
2649
2650    public void setDefaultValue(FieldItem field, String value) {
2651        setDefaultValue(
2652            field,
2653            ClassRepository.get().getClass(GuiAC.class).getMethod(
2654                "getDefaultValue"),
2655            value);
2656    }
2657
2658    public static boolean hasDefaultValue(FieldItem field) {
2659        return field.getAttribute(DYN_DEFAULT_VALUE) != null;
2660    }
2661
2662    public static boolean isEditableChoice(FieldItem field) {
2663        return field.getBoolean(EDITABLE_CHOICE, false);
2664    }
2665
2666    public void setDynamicFieldChoice(
2667        FieldItem field,
2668        Boolean editable,
2669        ClassItem targetClass,
2670        String targetMethod)
2671    {
2672        setDynamicFieldChoice(
2673            field,
2674            editable,
2675            targetClass.getMethod(targetMethod));
2676    }
2677
2678    public void setDynamicFieldChoice(
2679        FieldItem field,
2680        CollectionItem targetField)
2681    {
2682        field.setAttribute(FIELD_CHOICE, targetField);
2683        field.setAttribute(EDITABLE_CHOICE, Boolean.TRUE);
2684    }
2685
2686    public void setDynamicFieldChoice(
2687        FieldItem field,
2688        Boolean editable,
2689        MethodItem targetMethod)
2690    {
2691        field.setAttribute(FIELD_CHOICE, targetMethod);
2692        field.setAttribute(EDITABLE_CHOICE, editable);
2693    }
2694
2695    public void setMethodDynamicParameterChoice(
2696        MethodItem method,
2697        ClassItem[] targetClasses,
2698        String[] targetMethods,
2699        boolean[] editable)
2700    {
2701        MethodItem[] methods =
2702            new MethodItem[method.getParameterTypes().length];
2703        for (int i = 0; i < methods.length; i++) {
2704            if (targetClasses[i] != null && !targetClasses[i].equals("")) {
2705                methods[i] = targetClasses[i].getMethod(targetMethods[i]);
2706            } else {
2707                methods[i] = null;
2708            }
2709        }
2710        setMethodDynamicParameterChoice(method,methods,editable);
2711    }
2712
2713    public void setMethodDynamicParameterChoice(
2714        MethodItem method,
2715        MethodItem[] targetMethods,
2716        boolean[] editable)
2717    {
2718        method.setAttribute(PARAMETER_CHOICES, targetMethods);
2719        method.setAttribute(EDITABLE_CHOICES, editable);
2720    }
2721
2722    public void setDynamicClassChoice(String className, MethodItem targetMethod) {
2723        MetaItem cli = ClassRepository.get().getVirtualClass(className);
2724        cli.setAttribute(CLASS_CHOICES,targetMethod);
2725    }
2726
2727    public void setCollectionType(CollectionItem collection, String type) {
2728        collection.setAttribute(
2729            COLLECTION_TYPE,
2730            ClassRepository.get().getClass(type));
2731    }
2732
2733    /**
2734     * Sets the selection mode for an URL.
2735     *
2736     * @param field the field (of URL type)
2737     * @param mode the selection mode (DIRECTORIES_ONLY ||
2738     * FILES_AND_DIRECTORIES), default is FILES_ONLY
2739     * @param extensions the selection extensions (gif, ps, etc.)
2740     * @param extensionsDescription the description of the extensions
2741     * (can be null)
2742     */

2743    public void setURLSelectionMode(
2744        FieldItem field,
2745        String mode,
2746        String[] extensions,
2747        String extensionsDescription)
2748    {
2749        field.setAttribute(FILE_SELECTION_MODE, mode);
2750        field.setAttribute(FILE_EXTENSIONS, extensions);
2751        field.setAttribute(FILE_EXTENSIONS_DESCRIPTION, extensionsDescription);
2752    }
2753
2754    /*
2755      public void addAllowedFileExtensions(
2756      FieldItem field,
2757      String[] fileExtensions,
2758      String fileDescription)
2759      {
2760      FileEditorConfig config = (FileEditorConfig)field.getAttribute(FILE_EDITOR_CONFIG);
2761      if (config==null) {
2762      config = new FileEditorConfig();
2763      field.setAttribute(FILE_EDITOR_CONFIG,config);
2764      }
2765      }
2766    */

2767
2768    public void setViewOnSelection(CollectionItem collection) {
2769        collection.setAttribute(VIEW_ON_SELECTION, Boolean.TRUE);
2770    }
2771
2772    /**
2773     * Tells wether VIEW_ON_SELECTION is set for a given field. Defaults to true.
2774     * @param field the field
2775     * @return true if VIEW_ON_SELECTION is set for the field
2776     * @see #setViewOnSelection(CollectionItem)
2777     */

2778    public static boolean getViewOnSelection(FieldItem field) {
2779        return field.getBoolean(VIEW_ON_SELECTION, true);
2780    }
2781
2782    public void setOnSelection(
2783        CollectionItem collection,
2784        MethodItem eventHandler)
2785    {
2786        collection.setAttribute(SELECTION_HANDLER, eventHandler);
2787    }
2788
2789    public void setSelectionTarget(
2790        CollectionItem collection,
2791        ClassItem targetClass,
2792        String targetField)
2793    {
2794        collection.setAttribute(
2795            SELECTION_TARGET,
2796            targetClass.getField(targetField));
2797    }
2798
2799    public static MethodItem getSelectionHandler(MemberItem member) {
2800        Object handler = member.getAttribute(SELECTION_HANDLER);
2801        return (handler instanceof MethodItem) ? (MethodItem) handler : null;
2802    }
2803
2804    public void setPreferredHeight(CollectionItem collection, Length height) {
2805        collection.setAttribute(VIEW_HEIGHT, height);
2806    }
2807
2808    public void setPreferredWidth(CollectionItem collection, Length width) {
2809        collection.setAttribute(VIEW_WIDTH, width);
2810    }
2811
2812    public void setNumRowsPerPage(CollectionItem collection, int numRows) {
2813        collection.setAttribute(NUM_ROWS_PER_PAGE, new Integer(numRows));
2814    }
2815
2816    public void setAvailableNumRowsPerPage(CollectionItem collection, int[] numRows) {
2817        collection.setAttribute(AVAILABLE_NUM_ROWS_PER_PAGE, numRows);
2818    }
2819
2820    public static int[] getAvailableNumRowsPerPage(CollectionItem collection) {
2821        return (int[])collection.getAttribute(AVAILABLE_NUM_ROWS_PER_PAGE);
2822    }
2823
2824    static int defaultNumRowsPerPage = 10;
2825
2826    public static int getNumRowsPerPage(CollectionItem collection) {
2827        Object numRows = collection.getAttribute(NUM_ROWS_PER_PAGE);
2828        if (numRows == null)
2829            return defaultNumRowsPerPage;
2830        else
2831            return ((Integer) numRows).intValue();
2832    }
2833
2834    /**
2835     * Gets start index for collection view from the context
2836     * @param collection the collection to get the start index of
2837     */

2838    public static int getStartIndex(CollectionItem collection) {
2839        Map startIndexes =
2840            (Map) Collaboration.get().getAttribute(START_INDEXES);
2841        if (startIndexes == null) {
2842            return 0;
2843        } else {
2844            Object value = startIndexes.get(collection);
2845            if (value == null)
2846                return 0;
2847            else
2848                return ((Integer) value).intValue();
2849        }
2850    }
2851
2852    /**
2853     * Sets the start index for a collection view in the context
2854     * @param collection the collection
2855     * @param index the start index
2856     */

2857    public static void setStartIndex(CollectionItem collection, int index) {
2858        Map startIndexes =
2859            (Map) Collaboration.get().getAttribute(START_INDEXES);
2860        if (startIndexes == null) {
2861            startIndexes = new HashMap();
2862            Collaboration.get().addAttribute(START_INDEXES, startIndexes);
2863        }
2864
2865        startIndexes.put(collection, new Integer(index));
2866    }
2867
2868    public static void removeStartIndex(CollectionItem collection) {
2869        Map startIndexes =
2870            (Map) Collaboration.get().getAttribute(START_INDEXES);
2871        if (startIndexes != null) {
2872            startIndexes.remove(collection);
2873        }
2874    }
2875
2876    public void setFileChooserView(
2877        MethodItem method,
2878        String[] fileExtensions,
2879        String fileDescription)
2880    {
2881        method.setAttribute(
2882            FILE_CHOOSER_VIEW,
2883            new Object[] { fileExtensions, fileDescription });
2884        return;
2885    }
2886
2887    /**
2888     * Tells if the given method call by the GUI opens a file chooser
2889     * dialog.<p>
2890     *
2891     * @param setter the setter for the field
2892     * @return true if a file chooser is oppened
2893     * @see #getFileExtensions(MethodItem)
2894     * @see #getFileDescription(MethodItem) */

2895
2896    public boolean isFileChooserView(MethodItem setter) {
2897        return setter.getAttribute(FILE_CHOOSER_VIEW) != null;
2898    }
2899
2900    /**
2901     * Gets the file extensions for a given field that is view as a
2902     * file chooser (more precisely, the field that is set by the given
2903     * setter).<p>
2904     *
2905     * For instance, the file extensions can be a strings array like
2906     * {"gif", "jpg", "png"} or {"txt", "doc"}.<p>
2907     *
2908     * @param setter the setter for the field
2909     * @return the description of the files that are associated to the
2910     * field
2911     * @see #isFileChooserView(MethodItem) */

2912
2913    public String[] getFileExtensions(MethodItem setter) {
2914        Object attr = setter.getAttribute(FILE_CHOOSER_VIEW);
2915        if (attr != null) {
2916            return (String[]) ((Object[]) attr)[0];
2917        }
2918        return null;
2919    }
2920
2921    /**
2922     * Gets the file description for a given field that is view as a
2923     * file chooser (more precisely, the field that is set by the given
2924     * setter).<p>
2925     *
2926     * For instance, the file description can be a string like "Image
2927     * files" or "Text files".<p>
2928     *
2929     * @param setter the setter for the field
2930     * @return the description of the files that are associated to the
2931     * field
2932     * @see #isFileChooserView(MethodItem) */

2933
2934    public String getFileDescription(MethodItem setter) {
2935        Object attr = setter.getAttribute(FILE_CHOOSER_VIEW);
2936        if (attr != null) {
2937            return (String) ((Object[]) attr)[1];
2938        }
2939        return null;
2940    }
2941
2942    /**
2943     * Returns true if the given item must be displayed by the GUI as a
2944     * table.<p>
2945     *
2946     * @param collection the collection to check
2947     */

2948    public static boolean isTableView(CollectionItem collection) {
2949        return (collection.getBoolean(TABLE_VIEW, false))
2950            || (collection.isMap() && !RttiAC.isIndex(collection));
2951    }
2952
2953    public static boolean isChoiceView(CollectionItem collection) {
2954        return collection.getBoolean(CHOICE_VIEW,false);
2955    }
2956
2957    public static boolean isExternalChoiceView(CollectionItem collection) {
2958        return (collection.getBoolean(CHOICE_VIEW, false));
2959    }
2960
2961    public void setCreationAllowedParameters(
2962        AbstractMethodItem method,
2963        boolean[] create) {
2964        method.setAttribute(CREATION_ALLOWED_PARAMETERS, create);
2965    }
2966
2967    public void setCreationAllowed(FieldItem field, boolean allow) {
2968        field.getSetter().setAttribute(
2969            CREATION_ALLOWED_PARAMETERS,
2970            new boolean[] { allow });
2971    }
2972
2973    /**
2974     * Tells wether to display a "new" button for a parameter of a method
2975     *
2976     * @param method the method
2977     * @param i index of the parameter
2978     * @return a boolean
2979     *
2980     * @see #setCreationAllowedParameters(AbstractMethodItem,boolean[])
2981     */

2982    public static boolean isCreationAllowedParameter(
2983        AbstractMethodItem method,
2984        int i) {
2985        boolean[] cs =
2986            (boolean[]) method.getAttribute(CREATION_ALLOWED_PARAMETERS);
2987        if (cs == null) {
2988            return Wrappee.class.isAssignableFrom(
2989                method.getParameterTypes()[i]);
2990            /*
2991              if (i==0 && ((MethodItem)method).getSetField()!=null) {
2992              return true;
2993              } else {
2994              return false;
2995              }
2996            */

2997        }
2998        return cs[i];
2999    }
3000
3001    public void setParameterNames(
3002        AbstractMethodItem method,
3003        String[] parameterNames)
3004    {
3005        method.setAttribute(PARAMETER_NAMES, parameterNames);
3006        int count = method.getParameterCount();
3007        if (parameterNames.length!=count) {
3008            warning("setParameterNames: expecting "+count+" parameterNames for "+
3009                    method+", got "+parameterNames.length);
3010        }
3011    }
3012
3013    /**
3014     * Returns the parameter names of a method. If none were with
3015     * <code>setParameterNames</code>, try some naming convention
3016     * heuristic.
3017     * @param method the method
3018     * @return the parameter names of the method
3019     * @see #setParameterNames(AbstractMethodItem,String[])
3020     * @see #setParameterNames(AbstractMethodItem,String[])
3021     */

3022    public static String[] getParameterNames(AbstractMethodItem method) {
3023        String[] parameterNames =
3024            (String[]) method.getAttribute(PARAMETER_NAMES);
3025        if (parameterNames == null && method instanceof MethodItem) {
3026            MethodItem m = (MethodItem) method;
3027            if (m.isSetter()) {
3028                parameterNames = new String[] { getLabel(m.getSetField())};
3029            } else if (m.isRemover()) {
3030                parameterNames =
3031                    new String[] { getLabel(m.getRemovedCollections()[0])};
3032            } else if (m.isAdder()) {
3033                String collName = getLabel(m.getAddedCollections()[0]);
3034                if (method.getParameterCount() == 1) {
3035                    parameterNames = new String[] { NamingConventions.getSingular(collName) };
3036                } else if (method.getParameterCount() == 2) {
3037                    parameterNames = new String[] { "key", collName };
3038                }
3039            }
3040        }
3041        return parameterNames;
3042    }
3043
3044    public void setParameterFields(
3045        AbstractMethodItem method,
3046        String[] parameterFields)
3047    {
3048        method.setAttribute(PARAMETER_FIELDS, parameterFields);
3049    }
3050
3051    public void setPasswordParameters(
3052        AbstractMethodItem method,
3053        String[] params)
3054    {
3055        method.setAttribute(PASSWORD_PARAMETERS, params);
3056    }
3057
3058    public void setDirectCollectionMethods(
3059        CollectionItem collection,
3060        String[] methods)
3061    {
3062        collection.setAttribute(
3063            DIRECT_COLLECTION_METHODS,
3064            collection.getComponentType().getMethods(methods));
3065    }
3066
3067    public void setDefaultValues(AbstractMethodItem method, Object[] values) {
3068        method.setAttribute(DEFAULT_VALUES, values);
3069    }
3070
3071    public void setDefaultsAttributesOrder(
3072        ClassItem cl,
3073        String[] attributeNames)
3074    {
3075        cl.setAttribute(
3076            DEFAULTS_ATTRIBUTES_ORDER,
3077            cl.getFields(attributeNames));
3078    }
3079
3080    public static FieldItem[] getDefaultsAttributesOrder(ClassItem cl) {
3081        return (FieldItem[]) cl.getAttribute(DEFAULTS_ATTRIBUTES_ORDER);
3082    }
3083
3084    public void setClosingMethod(ClassItem classItem, String methodName) {
3085        AbstractMethodItem method = classItem.getAbstractMethod(methodName);
3086        method.setAttribute("GuiAC.closingMethod", Boolean.TRUE);
3087    }
3088
3089    public void setModifyingBoxes(
3090        ClassItem classItem,
3091        String methodName,
3092        String[] modifyingBoxes)
3093    {
3094        AbstractMethodItem method = classItem.getAbstractMethod(methodName);
3095        method.setAttribute("GuiAC.modifyingBoxes", modifyingBoxes);
3096    }
3097
3098    /**
3099     * Get the modifying boxes for the given abstract method item (a
3100     * method or a constructor).<p>
3101     *
3102     * @return the mofifying boxes names for each parameter */

3103
3104    public String[] getModifyingBoxes(AbstractMethodItem method) {
3105        return (String[]) method.getAttribute("GuiAC.modifyingBoxes");
3106    }
3107
3108    /**
3109     * Tells the swing gui to capture System.out so that it appears a
3110     * in tab.
3111     */

3112
3113    public void captureSystemOut() {
3114        /*
3115          ProgramView pv = (ProgramView)getDisplay("admin");
3116          if (pv != null)
3117          pv.captureSystemOut();
3118          else
3119          Log.warning("gui","captureSystemOut(): no ProgramView found");
3120        */

3121    }
3122
3123    public void captureSystemErr() {
3124        /*
3125          ProgramView pv = (ProgramView)getDisplay("admin");
3126          if (pv != null)
3127          pv.captureSystemErr();
3128          else
3129          Log.warning("gui","captureSystemErr(): no ProgramView found");
3130        */

3131    }
3132
3133    String defaultCurrency;
3134
3135    public void setDefaultCurrency(String currencyName, int precision) {
3136        MetaItem classItem =
3137            (MetaItem) ClassRepository.get().getVirtualClass("currency");
3138        classItem.setAttribute("gui.defaultCurrency", currencyName);
3139        declareCurrency(currencyName, precision, 1);
3140    }
3141
3142    /**
3143     * Returns the default currency
3144     */

3145    public static String getDefaultCurrency() {
3146        MetaItem classItem =
3147            (MetaItem) ClassRepository.get().getVirtualClass("currency");
3148        return (String) classItem.getAttribute("gui.defaultCurrency");
3149    }
3150
3151    public void declareCurrency(
3152        String currencyName,
3153        int precision,
3154        double rate)
3155    {
3156        MetaItem classItem =
3157            (MetaItem) ClassRepository.get().getVirtualClass("currency");
3158        logger.debug("currency classItem = " + classItem);
3159        Hashtable currencies =
3160            (Hashtable) classItem.getAttribute("gui.currencies");
3161        if (currencies == null) {
3162            logger.debug("building currencies");
3163            currencies = new Hashtable();
3164            classItem.setAttribute("gui.currencies", currencies);
3165        }
3166        currencies.put(
3167            currencyName,
3168            new Currency(currencyName, precision, rate));
3169        logger.debug("declareCurrency " + currencyName + " " + rate);
3170    }
3171    /**
3172     * Returns an enumeration of all declared currencies, including the
3173     * default currency.
3174     *
3175     * @return the declared currencies as an Enumeration of
3176     * Currency.
3177     */

3178    public static Enumeration getCurrencies() {
3179        MetaItem classItem =
3180            (MetaItem) ClassRepository.get().getVirtualClass("currency");
3181        Hashtable currencies =
3182            (Hashtable) classItem.getAttribute("gui.currencies");
3183        logger.debug(currencies.size() + " currencies");
3184        return currencies.keys();
3185    }
3186    /**
3187     * Returns the Currency object associated with a currency name.
3188     */

3189    public static Currency getCurrency(String currencyName) {
3190        MetaItem classItem =
3191            (MetaItem) ClassRepository.get().getVirtualClass("currency");
3192        Hashtable currencies =
3193            (Hashtable) classItem.getAttribute("gui.currencies");
3194        return (Currency) currencies.get(currencyName);
3195    }
3196
3197    // guiType -> ViewFactories
3198
static Hashtable viewFactories = new Hashtable();
3199
3200    /**
3201     * Returns a ViewFactory for a given guiType
3202     *
3203     * @param guiType the type of the gui ("swing","web",...)
3204     */

3205    public static ViewFactory getViewFactory(String guiType) {
3206        ViewFactory result = (ViewFactory) viewFactories.get(guiType);
3207        if (result == null) {
3208            loggerFactory.debug(
3209                "Creating a ViewFactory for the \"" + guiType + "\" gui");
3210            result = new ViewFactory();
3211            ViewFactory.init(guiType, result);
3212            viewFactories.put(guiType, result);
3213        }
3214        return result;
3215    }
3216
3217    /**
3218     * Set the view constructor for a given gui type.
3219     * @param guiType the type of the gui ("swing","web",...)
3220     * @param viewType the type of the view
3221     * @param constructor the view constructor for this gui type and view type
3222     */

3223    public void setViewConstructor(
3224        String guiType,
3225        String viewType,
3226        AbstractMethodItem constructor)
3227    {
3228        getViewFactory(guiType).setViewConstructor(viewType, constructor);
3229    }
3230
3231    // Dates
3232

3233    public void setDateFormat(String dateFormat) {
3234        ClassRepository.get().getClass("java.util.Date").setAttribute(
3235            "DATE_FORMAT",
3236            dateFormat);
3237    }
3238
3239    /**
3240     * Returns the date format as set by setDateFormat.
3241     *
3242     * @return the date format
3243     */

3244    public static String getDateFormat() {
3245        String format =
3246            (String) ClassRepository.get().getClass(
3247                "java.util.Date").getAttribute(
3248                    "DATE_FORMAT");
3249        if (format == null)
3250            format = "dd/MM/yyyy";
3251        return format;
3252    }
3253
3254    public void setDateHourFormat(String dateFormat) {
3255        ClassRepository.get().getClass("java.util.Date").setAttribute(
3256            DATEHOUR_FORMAT,
3257            dateFormat);
3258    }
3259
3260    /**
3261     * Returns the date format for DateHours as set by setDateHourFormat.
3262     *
3263     * @return the date format
3264     */

3265    public static String getDateHourFormat() {
3266        String format =
3267            (String) ClassRepository.get().getClass(
3268                "java.util.Date").getAttribute(
3269                    DATEHOUR_FORMAT);
3270        if (format == null)
3271            format = "dd/MM/yyyy HH:mm";
3272        return format;
3273    }
3274
3275    /**
3276     * Returns the default display format of floats.
3277     */

3278    public static String getFloatFormat() {
3279        String format =
3280            (String) ClassRepository.get().getClass(
3281                "java.lang.Float").getAttribute(
3282                    FLOAT_FORMAT);
3283        if (format == null)
3284            format = "0.00";
3285        return format;
3286    }
3287
3288    public void setFloatFormat(FieldItem field, String format) {
3289        field.setAttribute(FLOAT_FORMAT, format);
3290    }
3291
3292    /**
3293     * Returns the default display format of integers.
3294     */

3295    public static String getIntFormat() {
3296        String format =
3297            (String) ClassRepository.get().getClass(
3298                "java.lang.Integer").getAttribute(FORMAT);
3299        if (format == null)
3300            format = "0";
3301        return format;
3302    }
3303
3304    public void setIntFormat(FieldItem field, String format) {
3305        field.setAttribute(INT_FORMAT, format);
3306    }
3307
3308    public void setFormat(String className, String format) {
3309        MetaItem metaItem = ClassRepository.get().getVirtualClass(className);
3310        metaItem.setAttribute(FORMAT, format);
3311    }
3312
3313    /**
3314     * Returns the format of a ClassItem or VirtualClassItem.
3315     * @see #setFormat(String,String)
3316     */

3317    public static String getFormat(MetaItem item) {
3318        return (String) item.getAttribute(FORMAT);
3319    }
3320
3321    /**
3322     * Returns the display format of an item.
3323     */

3324    public static String getFloatFormat(MetaItem item) {
3325        String format = (String) item.getAttribute(FLOAT_FORMAT);
3326        if (format == null)
3327            format = getFloatFormat();
3328        return format;
3329    }
3330
3331    /**
3332     * Returns the display format of an item.
3333     */

3334    public static String getIntFormat(MetaItem item) {
3335        String format = (String) item.getAttribute(INT_FORMAT);
3336        if (format == null)
3337            format = getIntFormat();
3338        return format;
3339    }
3340
3341    public void setCommitOnFocusLost(boolean value) {
3342        /*
3343          ClassRepository.get().getClass("org.objectweb.jac.aspects.gui.SwingObjectView").setAttribute(
3344          "gui.commitOnFocusLost",
3345          ExtBoolean.valueOf(value)
3346          );
3347        */

3348    }
3349
3350    public static boolean getCommitOnFocusLost() {
3351        return true;
3352        /*
3353          Boolean val = (Boolean)ClassRepository.get().getClass("org.objectweb.jac.aspects.gui.SwingObjectView").
3354          getAttribute("gui.commitOnFocusLost");
3355          if (val == null)
3356          return true;
3357          else
3358          return val.booleanValue();
3359        */

3360    }
3361
3362    public void setDescription(ClassItem classItem, String description) {
3363        classItem.setAttribute(DESCRIPTION, description);
3364    }
3365
3366    public void setDescription(MemberItem member, String description) {
3367        member.setAttribute(DESCRIPTION, description);
3368    }
3369
3370    /**
3371     * Returns the description of an object if it has been set.
3372     */

3373
3374    public static String getDescription(Object object) {
3375        return getDescription(object, null, null);
3376    }
3377
3378    public static String getDescription(
3379        Object object,
3380        String beforeString,
3381        String afterString)
3382    {
3383        String expr =
3384            (String) ClassRepository.get().getClass(object).getAttribute(
3385                DESCRIPTION);
3386        if (expr == null)
3387            return null;
3388        else
3389            return parseFormatExpression(
3390                expr,
3391                object,
3392                beforeString,
3393                afterString);
3394    }
3395
3396    public void setLabel(ClassItem classItem, String label) {
3397        classItem.setAttribute(LABEL, label);
3398    }
3399
3400    public void setLabel(MemberItem member, String label) {
3401        member.setAttribute(LABEL, label);
3402    }
3403
3404    public void setLabel(
3405        MemberItem member,
3406        MemberItem selector,
3407        String label)
3408    {
3409        Map rules = (Map) member.getAttributeAlways(CONTEXTUAL_LABEL);
3410        if (rules == null) {
3411            rules = new HashMap();
3412            member.setAttribute(CONTEXTUAL_LABEL, rules);
3413        }
3414        rules.put(selector, label);
3415    }
3416
3417    public static String getLabel(MetaItem item) {
3418        return getLabel(item, null);
3419    }
3420
3421    /**
3422     * Returns the label of an item, or an automatically computed
3423     * string if none was set.
3424     * @param item the MetaItem
3425     * @return the label of the MetaItem
3426     */

3427    public static String getLabel(MetaItem item, Stack context) {
3428        String label = (String) item.getAttribute(LABEL);
3429        if (context != null) {
3430            label =
3431                (String) getContextAttribute(item,
3432                                             CONTEXTUAL_LABEL,
3433                                             context,
3434                                             label);
3435        }
3436        if (label == null) {
3437            label = NamingConventions.textForName(item.getName());
3438        }
3439        if (label==null)
3440            logger.warn("No label for "+item);
3441        return label;
3442    }
3443
3444    public void setMnemonics(MemberItem method, String mnemonics) {
3445        method.setAttribute(MNEMONICS,mnemonics);
3446    }
3447
3448    public void setMnemonics(ClassItem cli, String mnemonics) {
3449        cli.setAttribute(MNEMONICS,mnemonics);
3450    }
3451
3452    public static String getMnemonics(MetaItem item) {
3453        String mnemonics = (String)item.getAttribute(MNEMONICS);
3454        return mnemonics!=null ? mnemonics : "";
3455    }
3456
3457    public static String getMnemonics(MethodItem method) {
3458        String mnemonics = (String)method.getAttribute(MNEMONICS);
3459        if (mnemonics==null) {
3460            if (method.isSetter()) {
3461                mnemonics = getMnemonics(method.getSetField());
3462            } else if (method.isGetter()) {
3463                mnemonics = getMnemonics(method.getReturnedField());
3464            } else if (method.isAdder()) {
3465                mnemonics = getMnemonics(method.getAddedCollection());
3466            } else if (method.isRemover()) {
3467                mnemonics = getMnemonics(method.getRemovedCollection());
3468            }
3469        }
3470        return mnemonics!=null ? mnemonics : "";
3471    }
3472
3473    Hashtable enums = new Hashtable();
3474
3475    public void defineEnum(String name, String[] values, int start, int step) {
3476        enums.put(name, new Enum(values, start, step));
3477    }
3478
3479    public void setDisplayLabel(MemberItem member, boolean displayLabel) {
3480        member.setAttribute(DISPLAY_LABEL, ExtBoolean.valueOf(displayLabel));
3481    }
3482
3483    public void setDisplayLabel(String itemName, boolean displayLabel) {
3484        MetaItem metaItem = ClassRepository.get().getVirtualClass(itemName);
3485        metaItem.setAttribute(DISPLAY_LABEL, ExtBoolean.valueOf(displayLabel));
3486    }
3487
3488    public void setViewableItems(CollectionItem collection, boolean viewable) {
3489        setViewableItems(collection,DEFAULT_VIEW,viewable);
3490    }
3491
3492    public void setViewableItems(CollectionItem collection, String viewName, boolean viewable) {
3493        getView(collection,viewName).setViewableItems(viewable);
3494    }
3495
3496    public void setEnableLinks(CollectionItem collection, String viewName, boolean enable) {
3497        getView(collection,viewName).setEnableLinks(enable);
3498    }
3499
3500    public void setEnableLinks(ClassItem cli, String viewName, boolean enable) {
3501        getView(cli,viewName).setEnableLinks(enable);
3502    }
3503
3504    public void setCellViewType(CollectionItem collection, String viewName,
3505                                FieldItem field, String viewType) {
3506        getView(collection,viewName).setViewType(field,viewType);
3507    }
3508
3509    /**
3510     * Converts the a String into an object for the value of a field
3511     * @param field the field for which to convert the value
3512     * @param value the string to convert
3513     * @return an object of the type of the field whose string
3514     * representation is <em>value</em>, or null.
3515     */

3516    public static Object getDefaultValue(FieldItem field, String value) {
3517        //System.out.println("GET_DEFAULT_VALUE: "+field+ ", " + field.getType());
3518
Collection objects =
3519            ObjectRepository.getObjects(
3520                ClassRepository.get().getClass(field.getType()));
3521        Iterator i = objects.iterator();
3522        while (i.hasNext()) {
3523            Object obj = i.next();
3524            //System.out.println("TESTING: "+GuiAC.toString(obj));
3525
if (GuiAC.toString(obj).equals(value)) {
3526                                //System.out.println("RETURN: "+obj);
3527
return obj;
3528            }
3529        }
3530        return null;
3531    }
3532
3533    public String[] getDefaultConfigs() {
3534        return new String[] {
3535            "org/objectweb/jac/aspects/gui/gui.acc",
3536            /*"org/objectweb/jac/aspects/gui/swing/gui.acc", */
3537            "org/objectweb/jac/aspects/gui/web/gui.acc",
3538            "org/objectweb/jac/aspects/authentication/gui.acc",
3539            "org/objectweb/jac/aspects/user/gui.acc" };
3540    }
3541
3542    public void setNavBar(String gui, CollectionItem collection) {
3543        CustomizedGUI cgui = (CustomizedGUI) getCustomized(gui);
3544        if (cgui == null) {
3545            error(gui+" has not been declared with registerCustomized");
3546            return;
3547        }
3548
3549        Vector vect = (Vector) collection.getAttribute(NAVBAR);
3550
3551        if (vect == null) {
3552            vect = new Vector();
3553            collection.setAttribute(NAVBAR, vect);
3554        }
3555        if (!vect.contains(cgui)) {
3556            vect.add(cgui);
3557        }
3558    }
3559
3560    public static boolean hasSetNavBar(
3561        CustomizedGUI gui,
3562        CollectionItem coll)
3563    {
3564        Vector vect = (Vector) coll.getAttribute(NAVBAR);
3565        return vect != null && vect.contains(gui);
3566    }
3567
3568    public void addViewFieldDependency(ClassItem cl, String fieldName) {
3569        Collection fields =
3570            (Collection) cl.getAttributeAlways(FIELD_DEPENDENCIES);
3571        if (fields == null) {
3572            fields = new Vector();
3573            cl.setAttribute(FIELD_DEPENDENCIES, fields);
3574        }
3575        fields.add(cl.getField(fieldName));
3576    }
3577
3578    public void setInteractionHandler(MethodItem method, MethodItem handler) {
3579        if (!handler.isStatic())
3580            error("handler method must be static");
3581        else
3582            method.setAttribute(INTERACTION_HANDLER, handler);
3583    }
3584
3585    public static MethodItem getInteractionHandler(AbstractMethodItem method) {
3586        return (MethodItem) method.getAttribute(INTERACTION_HANDLER);
3587    }
3588
3589    /**
3590     * Returns the fields the views a class depend on.
3591     * @param cli the class
3592     * @return a collection of FieldItem
3593     * @see #addViewFieldDependency(ClassItem,String)
3594     */

3595    public static Collection getDependentFields(ClassItem cli) {
3596        return (Collection) cli.getAttribute(FIELD_DEPENDENCIES);
3597    }
3598
3599    public static long dialogTimeout = 1000 * 60 * 20; // 20 minutes
3600
public void setDialogTimeout(long timeout) {
3601        dialogTimeout = timeout;
3602    }
3603
3604    static String labelAdd = "add";
3605    public void setLabelAdd(String label) {
3606        labelAdd = label;
3607    }
3608    public static String getLabelAdd() {
3609        return labelAdd;
3610    }
3611
3612    static String labelNew = "new";
3613    public void setLabelNew(String label) {
3614        labelNew = label;
3615    }
3616    public static String getLabelNew() {
3617        return labelNew;
3618    }
3619
3620    static String labelCancel = "Cancel";
3621    public void setLabelCancel(String label) {
3622        labelCancel = label;
3623    }
3624    public static String getLabelCancel() {
3625        return labelCancel;
3626    }
3627
3628    static String labelOK = "OK";
3629    public void setLabelOK(String label) {
3630        labelOK = label;
3631    }
3632    public static String getLabelOK() {
3633        return labelOK;
3634    }
3635
3636    static String labelClose = "Close";
3637    public void setLabelClose(String label) {
3638        labelClose = label;
3639    }
3640    public static String getLabelClose() {
3641        return labelClose;
3642    }
3643
3644    static String labelNone = "None";
3645    public void setLabelNone(String label) {
3646        labelNone = label;
3647    }
3648    public static String getLabelNone() {
3649        return labelNone;
3650    }
3651
3652    static String labelAll = "All";
3653    public void setLabelAll(String label) {
3654        labelAll = label;
3655    }
3656    public static String getLabelAll() {
3657        return labelAll;
3658    }
3659
3660    public void selectWithIndexedField(
3661        ClassItem cl,
3662        CollectionItem collection,
3663        String repositoryName)
3664    {
3665        cl.setAttribute(INDEXED_FIELD_SELECTOR, collection);
3666        cl.setAttribute(REPOSITORY_NAME, repositoryName);
3667    }
3668
3669    public void setIndexNotFoundHandler(ClassItem cl, MethodItem handler) {
3670        cl.setAttribute(INDEX_NOT_FOUND_HANDLER, handler);
3671    }
3672
3673    /**
3674     * Gets the repository object of a class
3675     * @param cl the class
3676     * @see #selectWithIndexedField(ClassItem,CollectionItem,String)
3677     */

3678    public static Object getRepository(ClassItem cl) {
3679        String repositoryName = (String) cl.getAttribute(REPOSITORY_NAME);
3680        if (repositoryName != null) {
3681            return NameRepository.get().getObject(repositoryName);
3682        } else {
3683            return null;
3684        }
3685    }
3686
3687    static String encoding = "UTF-8";
3688    public void setEncoding(String encoding) {
3689        this.encoding = encoding;
3690    }
3691    public static String getEncoding() {
3692        return encoding;
3693    }
3694}
3695
Popular Tags