A
download Actions.java
Language: Java
License: LGPL
Copyright: (C) 2002-2003 Laurent Martelli
LOC: 167
Project Info
Java Aspect Components(jac)
Server: ObjectWeb Forge
Type: cvs
...\objectweb\jac\aspects\gui\
   ...CollectionItemView.java
   AbstractNode.java
   Actions.java
   AddEvent.java
   BehaviorGuiConf.java
   Border.java
   Callback.java
   ...sAppearenceGuiConf.java
   ClassChooser.java
   CollectionEvent.java
   CollectionItemView.java
   CollectionModel.java
   CollectionPosition.java
   CollectionUpdate.java
   CollectionView.java
   CollectionWrapper.java
   ComboBoxModel.java
   CommitException.java
   CompositeView.java
   Constants.java
   Currency.java
   CustomizedDisplay.java
   CustomizedGUI.java
   CustomizedView.java
   DateFormat.java
   DateHourFormat.java
   DialogView.java
   DisplayContext.java
   EditorContainer.java
   Event.java
   EventHandler.java
   ExpressionListener.java
   ExprWatcher.java
   ExprWatcherParser.java
   ExtendedTableModel.java
   ...dAppearenceGuiConf.java
   FieldEditor.java
   FieldItemView.java
   FieldUpdate.java
   FieldView.java
   FileEditorConfig.java
   FilterCriteria.java
   FloatFormat.java
   Format.java
   GenericFactory.java
   gui.acc
   GuiAC.java
   GuiConf.java
   HandlerResult.java
   ...tCanceledException.java
   InputSequence.java
   InputWrapper.java
   IntFormat.java
   InvokeEvent.java
   InvokeThread.java
   Length.java
   LessAbstractListModel.java
   LinkGenerator.java
   ListModel.java
   MatrixUtils.java
   MemberItemView.java
   Menu.java
   MenuView.java
   ...dAppearenceGuiConf.java
   MethodItemView.java
   MethodUpdate.java
   MethodView.java
   Model.java
   NumberFormat.java
   ObjectChooserModel.java
   ObjectNode.java
   ObjectUpdate.java
   ObjectView.java
   package.html
   PanelContent.java
   PanelView.java
   PercentFormat.java
   PointFormat.java
   ReferenceEditor.java
   RelationNode.java
   RemoveEvent.java
   Reports.java
   ResourceManager.java
   RootNode.java
   SortCriteria.java
   StatusView.java
   SubstanceEvent.java
   TableCellViewer.java
   TableFilter.java
   TableMap.java
   TableModel.java
   TableSorter.java
   TabsView.java
   Target.java
   Template.java
   TemplateReader.java
   TimeoutException.java
   Transfer.java
   TreeListener.java
   TreeModel.java
   TreeView.java
   Unit.java
   Utils.java
   View.java
   ViewControlWrapper.java
   ViewFactory.java
   ViewIdentity.java
   Views.java
   WaitWrapper.java
   WindowView.java
   WrappableList.java
   WrappableMap.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
  Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com>
                          Renaud Pawlak <renaud@aopsys.com>
  
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA */

package org.objectweb.jac.aspects.gui;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.objectweb.jac.aspects.authentication.AuthenticationAC;
import org.objectweb.jac.aspects.session.SessionAC;
import org.objectweb.jac.core.ACManager;
import org.objectweb.jac.core.Collaboration;
import org.objectweb.jac.core.Display;
import org.objectweb.jac.core.NameRepository;
import org.objectweb.jac.core.Wrapping.MethodStat;
import org.objectweb.jac.core.Wrapping;
import org.objectweb.jac.core.rtti.AbstractMethodItem;
import org.objectweb.jac.core.rtti.ClassItem;
import org.objectweb.jac.core.rtti.ClassRepository;
import org.objectweb.jac.core.rtti.MetaItem;
import org.objectweb.jac.core.rtti.MethodItem;
import org.objectweb.jac.util.MimeTypes;

/**
 * This class is a container of commonly used GUI actions static
 * methods.
 *
 * <p>Usually, a GUI action takes in parameter the display
 * context. Using the context, is can then know the customized window
 * to use to interact with the users. When an action does not take any
 * display context, it means that it does not need any interaction
 * with the GUI or that the display context is retrieved throught the
 * collaboration.
 */
public class Actions {
    static final Logger logger = Logger.getLogger("gui");

    /**
     * Quit the application by shutting down the server.
     *
     * @param context the display context for this action
     */
    public static void exit(DisplayContext context) {
        Display display = context.getDisplay();
        if (display!=null)
            display.close();
        System.exit(0);
    }
   
    /**
     * Logout from an application by clearing the current user. If an
     * authentication aspect is woven, the user is asked again.
     *
     * @param context the display context for this action */

    public static void logout(DisplayContext context) {
        SessionAC sac = ((SessionAC)ACManager.getACM().getAC("session"));
        if (sac==null) {
            logger.error("No session aspect found: logout cannot work");
            return;
        }
        sac.clearCurrentSessionAttribute(AuthenticationAC.USER);
        Collaboration.get().removeAttribute(SessionAC.INITIALIZED);
        context.getDisplay().rebuildAllCustomized();
    }

    /**
     * Shows a message on the status bar of the current customized. If
     * no display context available, then <code>println</code> is
     * used.
     * 
     * @param message the message to show */

    public static void showStatus(String message) {
        CustomizedView cview = ((DisplayContext)Collaboration.get()
                                .getAttribute(GuiAC.DISPLAY_CONTEXT)).getCustomizedView();
        if(cview!=null) {
            cview.showStatus(message);
        }
    }

    /**
     * Show a customized window that has been declared and configured
     * within the GUI aspect.
     *
     * @param context the display context for this action
     * @param id the customized ID */

    public static void showWindow(DisplayContext context,String id) {
        ((GuiAC)ACManager.getACM().getAC("gui"))
            .createSwingDisplays(new String[] {id});
    }
  
    /**
     * Invokes a method on an object. */

    public static void invoke(Object object, String methodName) {
        AbstractMethodItem method = ClassRepository.get()
            .getClass(object).getMethod(methodName);
        EventHandler.get().onInvoke(
            (DisplayContext)Collaboration.get().getAttribute(GuiAC.DISPLAY_CONTEXT),
            new InvokeEvent(null,object,method));
    }

    /**
     * Display an object in a panel.
     *
     * @param context the DisplayContext of the custmoized view
     * @param objectName the name of the object to display
     * @param panelID the panel ID where to display the object
     *
     * @see #viewObject(DisplayContext,String,String)
     * @see #openView(DisplayContext,String)
     */
    public static void viewObject2(DisplayContext context, 
                                   String objectName, String viewName, 
                                   String panelID) 
    {
        CustomizedView custom = context.getCustomizedView();
        if (custom!=null) {
            ViewFactory factory = context.getDisplay().getFactory();
            Object object = NameRepository.get().getObject(objectName);
            if (object!=null)
                custom.getPanelView().addView(
                    factory.createView(
                        objectName,"Object",
                        new Object[] {viewName,object},
                        context),
                    panelID
                );
            else 
                custom.getPanelView().addView(
                    factory.createView("No such object "+objectName,"Label",context),
                    panelID
                );

            EventHandler.get().maybeInvalidatePane(
                context.getDisplay().getFactory(),context,
                custom,panelID);
        }
    }

    /**
     * Display an object in a panel.
     *
     * @param context the DisplayContext of the custmoized view
     * @param objectName the name of the object to display
     * @param panelID the panel ID where to display the object
     *
     * @see #viewObject2(DisplayContext,String,String,String)
     * @see #openView(DisplayContext,String)
     */
    public static void viewObject(DisplayContext context, 
                                  String objectName, String panelID) 
    {
        viewObject2(context,objectName,GuiAC.DEFAULT_VIEW,panelID);
    }

    /**
     * Display an object in a new window
     *
     * @param context the DisplayContext of the custmoized view
     * @param objectName the name of the object to display
     *
     * @see #viewObject2(DisplayContext,String,String,String)
     * @see #viewObject(DisplayContext,String,String)
     */
    public static void openView(DisplayContext context, 
                                String objectName) 
    {
        Object object = NameRepository.get().getObject(objectName);
        if (object!=null)
            context.getDisplay().show(object);
        else
            context.getDisplay().showError("Error","No such object "+objectName);
    }

    public static String getOpenViewIcon(MethodItem method, 
                                         Object object, Object[] parameters) {
        Object target = NameRepository.get().getObject((String)parameters[0]);
        if (target!=null)
            return GuiAC.getIcon(ClassRepository.get().getClass(target),target);
        else
            return null;
    }

    public static String getFileIcon(File file) {
        if (file.isDirectory())
            return ResourceManager.getResource("open_icon");
        else 
            return ResourceManager.getResource("doc_icon");
    }

    /**
     * Changes a trace for the current application
     * @param loggerName category of the trace
     * @param level level of the trace
     */
    public static void setTrace(String loggerName, Level level) {
        Logger.getLogger(loggerName).setLevel(level);
    }

    /**
     * Returns all known logger names
     */
    public static Collection getLoggerNames(Object substance) {
        Enumeration enumeration = LogManager.getCurrentLoggers();
        LinkedList loggers = new LinkedList();
        while (enumeration.hasMoreElements()) {
            loggers.add(((Logger)enumeration.nextElement()).getName());
        }
        return loggers;
    }

    /**
     * Returns all known loggers
     */
    public static Collection getLoggers(ClassItem cli) {
        Enumeration enumeration = LogManager.getCurrentLoggers();
        LinkedList loggers = new LinkedList();
        while (enumeration.hasMoreElements()) {
            loggers.add(enumeration.nextElement());
        }
        return loggers;
    }

    /**
     * Returns all known log levels
     */
    public static Collection getLogLevels(ClassItem cli) {
        ArrayList levels = new ArrayList(7);
        levels.add(Level.ALL);
        levels.add(Level.OFF);
        levels.add(Level.DEBUG);
        levels.add(Level.WARN);
        levels.add(Level.ERROR);
        levels.add(Level.INFO);
        levels.add(Level.FATAL);
        return levels;
    }

    static MimeTypes mimeTypes = new MimeTypes();
    public static Collection getMimeTypes(MetaItem cli) {
        return mimeTypes.getMimeTypes();
    }
    static {
        mimeTypes.readDefaults();
    }

    /**
     * Reloads an aspect for the current application
     */
    public static void reloadAspect(String aspect) throws Exception {
        ACManager.getACM().reloadAspect(aspect);
    }

    public static void printWrappingStatistics() {
        Map stats = Wrapping.getWrappingStatistics();
        Iterator i = stats.values().iterator();
        while(i.hasNext()) {
            MethodStat stat = (MethodStat)i.next();
            if (stat.getTotal()==0)
                System.out.println(stat.getMethod().getLongName()+" "+0);
            else
                System.out.println(stat.getMethod().getLongName()+" "+stat.getAverage());
        }
    }
    
    /**
     * Enable EJP profiling
     */
    /*
      public static void enableProfiling() throws Throwable {
      if (!ejp.tracer.TracerAPI.enableTracing()) {
      throw ejp.tracer.TracerAPI.getInitializationError();
      }
      }

      public static void disableProfiling() throws Throwable {
      if (!ejp.tracer.TracerAPI.disableTracing()) {
      throw ejp.tracer.TracerAPI.getInitializationError();
      }
      }
    */
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us