svn commit: r17451 - trunk/src/argouml-app/src/org/argouml: ui ui/explorer uml/diagram/ui

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-11-04 14:55:07-0800
New Revision: 17451

Added:
   trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactory.java
   trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactoryManager.java
Modified:
   trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java

Log:
First commit of new ContextActionFactory architecture

Added: trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactory.java?view=markup&pathrev=17451
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactory.java	2009-11-04 14:55:07-0800
@@ -0,0 +1,56 @@
+// $Id: ContextActionFactory.java 16277 2008-12-07 20:36:40Z bobtarling $
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies.  This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason.  IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.ui;
+
+import java.util.List;
+
+/**
+ * Interface for a factory of context popups, which are created based on a
+ * given object.
+ * 
+ * The factory creates an additional popup on the context menu for selected
+ * elements
+ * @author Enrico Da Ros
+ */
+public interface ContextActionFactory {
+    /**
+     * This method shall test the type of the given object,
+     * and if recognised, create a new Vector of Action 
+     * derived classes and null (for the separators). <p>
+     * 
+     * If the object type is not something this factory 
+     * knows how to deal with, then null shall be returned
+     * (do NOT throw an exception). <p>
+     * 
+     * If the given object falls within a class of objects 
+     * that this factory is the exclusive factory for,
+     * then it is allowed to throw an exception if 
+     * the object is invalid/unknown. However,
+     * be careful not to break the possibility to extend ArgoUML. 
+     * @param element the object to create a new context popup for
+     * @return the new menu structure or null
+     */
+    List createContextPopupActions(Object element);
+}

Added: trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactoryManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactoryManager.java?view=markup&pathrev=17451
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/ui/ContextActionFactoryManager.java	2009-11-04 14:55:07-0800
@@ -0,0 +1,103 @@
+// $Id: ContextActionFactoryManager.java 16277 2008-12-07 20:36:40Z bobtarling $
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies.  This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason.  IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.ui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.Action;
+import javax.swing.JSeparator;
+
+import org.argouml.ui.targetmanager.TargetManager;
+
+/**
+ * Manager of context meny factories registered in ArgoUML.
+ * <p>
+ * 
+ * You can add and remove a ContextPopupFactory instance to this central
+ * registry. The registered factories are then used when a new Context menu has
+ * to be build.
+ * 
+ * The factory creates an additional popup on the context menu
+ * 
+ * @author EnDaRos
+ */
+public class ContextActionFactoryManager {
+    private static List<ContextActionFactory> epfactories =
+        new ArrayList<ContextActionFactory>();
+
+    /**
+     * @param factory
+     *            add the given factory
+     */
+    public static void addContextPopupFactory(ContextActionFactory factory) {
+	epfactories.add(0, factory);
+    }
+
+    /**
+     * For modules, it would be useful to be able to remove their factories.
+     * <p>
+     * 
+     * TODO: The effect of this method is not yet tested!
+     * 
+     * @param factory
+     *            the factory to remove
+     */
+    public static void removeContextPopupFactory(ContextActionFactory factory) {
+	epfactories.remove(factory);
+    }
+
+    /**
+     * This method is not public since it is meant to be used exclusively by
+     * TabProps.
+     */
+    static Collection<ContextActionFactory> getFactories() {
+        return epfactories;
+    }
+
+    /**
+     * Adds to the default actions the new menus for the registered factories
+     * @return
+     */
+    public static List<Action> getContextPopupActions() {
+	List<Action> allActionsFound = new ArrayList<Action>();
+	Object element = TargetManager.getInstance().getSingleModelTarget();
+
+	List tmpActionsContainer = null;
+	for (ContextActionFactory factory : ContextActionFactoryManager
+				.getFactories()) {
+	    tmpActionsContainer = factory.createContextPopupActions(element);
+	    if (tmpActionsContainer != null && tmpActionsContainer.size() > 0) {
+		if (allActionsFound.size() > 0) {
+    	    	    allActionsFound.add(null);
+    	    	}
+   	    	allActionsFound.addAll(tmpActionsContainer);
+	    }
+	}
+	return allActionsFound;
+    }
+}

Modified: trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java?view=diff&pathrev=17451&r1=17450&r2=17451
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerPopup.java	2009-11-04 14:55:07-0800
@@ -48,6 +48,7 @@
 import org.argouml.profile.Profile;
 import org.argouml.ui.ActionCreateContainedModelElement;
 import org.argouml.ui.ActionCreateEdgeModelElement;
+import org.argouml.ui.ContextActionFactoryManager;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.diagram.ArgoDiagram;
 import org.argouml.uml.diagram.DiagramUtils;
@@ -211,6 +212,8 @@
             initMenuCreateDiagrams();
             this.add(createDiagrams);
         }
+        
+        initMenuCreateModuleActions();
 
         if (mutableModelElementsOnly) {
             initMenuCreateModelElements();
@@ -484,6 +487,14 @@
         }
     }
     
+    private void initMenuCreateModuleActions() {
+        final List<Action> modelElementMenuItems = 
+            ContextActionFactoryManager.getContextPopupActions();
+        for (Action a : modelElementMenuItems) {
+            add(a);
+        }
+    }
+    
     private void addCreateModelElementAction(
                 Set<JMenuItem> menuItems,
                 Object metaType,

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java?view=diff&pathrev=17451&r1=17450&r2=17451
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEdgeModelElement.java	2009-11-04 14:55:07-0800
@@ -80,6 +80,7 @@
 import org.argouml.notation.NotationSettings;
 import org.argouml.ui.ArgoJMenu;
 import org.argouml.ui.Clarifier;
+import org.argouml.ui.ContextActionFactoryManager;
 import org.argouml.ui.ProjectActions;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.StereotypeUtility;
@@ -309,6 +310,13 @@
         ActionList popUpActions =
             new ActionList(super.getPopUpActions(me), isReadOnly());
         
+        // Added this part to load the extra menu content
+        final List<Action> modulesActions =
+            ContextActionFactoryManager.getContextPopupActions();
+        if(modulesActions!=null && modulesActions.size()>0){
+            popUpActions.addAll(modulesActions);
+        }
+        
         // popupAddOffset should be equal to the number of items added here:
         popUpActions.add(new JSeparator());
         popupAddOffset = 1;

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java?view=diff&pathrev=17451&r1=17450&r2=17451
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigNodeModelElement.java	2009-11-04 14:55:07-0800
@@ -83,6 +83,7 @@
 import org.argouml.profile.FigNodeStrategy;
 import org.argouml.ui.ArgoJMenu;
 import org.argouml.ui.Clarifier;
+import org.argouml.ui.ContextActionFactoryManager;
 import org.argouml.ui.ProjectActions;
 import org.argouml.ui.UndoableAction;
 import org.argouml.ui.targetmanager.TargetManager;
@@ -586,6 +587,12 @@
         ActionList popUpActions =
             new ActionList(super.getPopUpActions(me), isReadOnly());
 
+        final List<Action> modulesActions =
+            ContextActionFactoryManager.getContextPopupActions();
+        if(modulesActions!=null && modulesActions.size()>0){
+            popUpActions.addAll(modulesActions);
+        }
+        
         // Show ...
         ArgoJMenu show = buildShowPopUp();
         if (show.getMenuComponentCount() > 0) {

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2414540

To unsubscribe from this discussion, e-mail: [[email protected]].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.