| 1 19 20 package org.objectweb.jac.aspects.gui; 21 22 import java.util.ArrayList; 23 import java.util.Collection; 24 import java.util.Enumeration; 25 import java.util.LinkedList; 26 import org.apache.log4j.Level; 27 import org.apache.log4j.LogManager; 28 import org.apache.log4j.Logger; 29 import org.objectweb.jac.aspects.authentication.AuthenticationAC; 30 import org.objectweb.jac.aspects.session.SessionAC; 31 import org.objectweb.jac.core.ACManager; 32 import org.objectweb.jac.core.Collaboration; 33 import org.objectweb.jac.core.Display; 34 import org.objectweb.jac.core.NameRepository; 35 import org.objectweb.jac.core.rtti.AbstractMethodItem; 36 import org.objectweb.jac.core.rtti.ClassItem; 37 import org.objectweb.jac.core.rtti.ClassRepository; 38 import org.objectweb.jac.core.rtti.MetaItem; 39 import org.objectweb.jac.core.rtti.MethodItem; 40 import org.objectweb.jac.util.MimeTypes; 41 import java.io.File; 42 43 53 54 public class Actions { 55 static Logger logger = Logger.getLogger("gui"); 56 57 62 public static void exit(DisplayContext context) { 63 Display display = context.getDisplay(); 64 if (display!=null) 65 display.close(); 66 System.exit(0); 67 } 68 69 74 75 public static void logout(DisplayContext context) { 76 SessionAC sac = ((SessionAC)ACManager.getACM().getAC("session")); 77 if (sac==null) { 78 logger.error("No session aspect found: logout cannot work"); 79 return; 80 } 81 sac.clearCurrentSessionAttribute(AuthenticationAC.USER); 82 Collaboration.get().removeAttribute(SessionAC.INITIALIZED); 83 context.getDisplay().fullRefresh(); 84 } 85 86 92 93 public static void showStatus(String message) { 94 CustomizedView cview = ((DisplayContext)Collaboration.get() 95 .getAttribute(GuiAC.DISPLAY_CONTEXT)).getCustomizedView(); 96 if(cview!=null) { 97 cview.showStatus(message); 98 } 99 } 100 101 107 108 public static void showWindow(DisplayContext context,String id) { 109 ((GuiAC)ACManager.getACM().getAC("gui")) 110 .createSwingDisplays(new String[] {id}); 111 } 112 113 115 116 public static void invoke(Object object, String methodName) { 117 AbstractMethodItem method = ClassRepository.get() 118 .getClass(object).getMethod(methodName); 119 EventHandler.get().onInvoke( 120 (DisplayContext)Collaboration.get().getAttribute(GuiAC.DISPLAY_CONTEXT), 121 new InvokeEvent(null,object,method)); 122 } 123 124 134 public static void viewObject2(DisplayContext context, 135 String objectName, String viewName, 136 String panelID) 137 { 138 CustomizedView custom = context.getCustomizedView(); 139 if (custom!=null) { 140 ViewFactory factory = context.getDisplay().getFactory(); 141 Object object = NameRepository.get().getObject(objectName); 142 if (object!=null) 143 custom.getPanelView().addView( 144 factory.createView( 145 objectName,"Object", 146 new Object[] {viewName,object}, 147 context), 148 panelID 149 ); 150 else 151 custom.getPanelView().addView( 152 factory.createView("No such object "+objectName,"Label",context), 153 panelID 154 ); 155 156 EventHandler.get().maybeInvalidatePane( 157 context.getDisplay().getFactory(),context, 158 custom,panelID); 159 } 160 } 161 162 172 public static void viewObject(DisplayContext context, 173 String objectName, String panelID) 174 { 175 viewObject2(context,objectName,GuiAC.DEFAULT_VIEW,panelID); 176 } 177 178 187 public static void openView(DisplayContext context, 188 String objectName) 189 { 190 Object object = NameRepository.get().getObject(objectName); 191 if (object!=null) 192 context.getDisplay().show(object); 193 else 194 context.getDisplay().showError("Error","No such object "+objectName); 195 } 196 197 public static String getOpenViewIcon(MethodItem method, 198 Object object, Object[] parameters) { 199 Object target = NameRepository.get().getObject((String)parameters[0]); 200 if (target!=null) 201 return GuiAC.getIcon(ClassRepository.get().getClass(target),target); 202 else 203 return null; 204 } 205 206 public static String getFileIcon(File file) { 207 if (file.isDirectory()) 208 return ResourceManager.getResource("open_icon"); 209 else 210 return ResourceManager.getResource("doc_icon"); 211 } 212 213 218 public static void setTrace(String loggerName, Level level) { 219 Logger.getLogger(loggerName).setLevel(level); 220 } 221 222 225 public static Collection getLoggerNames(Object substance) { 226 Enumeration enum = LogManager.getCurrentLoggers(); 227 LinkedList loggers = new LinkedList(); 228 while (enum.hasMoreElements()) { 229 loggers.add(((Logger)enum.nextElement()).getName()); 230 } 231 return loggers; 232 } 233 234 237 public static Collection getLoggers(ClassItem cli) { 238 Enumeration enum = LogManager.getCurrentLoggers(); 239 LinkedList loggers = new LinkedList(); 240 while (enum.hasMoreElements()) { 241 loggers.add(enum.nextElement()); 242 } 243 return loggers; 244 } 245 246 249 public static Collection getLogLevels(ClassItem cli) { 250 ArrayList levels = new ArrayList(7); 251 levels.add(Level.ALL); 252 levels.add(Level.OFF); 253 levels.add(Level.DEBUG); 254 levels.add(Level.WARN); 255 levels.add(Level.ERROR); 256 levels.add(Level.INFO); 257 levels.add(Level.FATAL); 258 return levels; 259 } 260 261 static MimeTypes mimeTypes = new MimeTypes(); 262 public static Collection getMimeTypes(MetaItem cli) { 263 return mimeTypes.getMimeTypes(); 264 } 265 static { 266 mimeTypes.readDefaults(); 267 } 268 269 272 public static void reloadAspect(String aspect) throws Exception { 273 ACManager.getACM().reloadAspect(aspect); 274 } 275 276 279 292 } 293 | Popular Tags |