svn commit: r13250 - trunk/src_new/org/argouml: application/api uml/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2007-08-05 14:36:16-0700
New Revision: 13250

Added:
   trunk/src_new/org/argouml/application/api/Predicate.java
Modified:
   trunk/src_new/org/argouml/uml/ui/TabSrc.java

Log:
Fix for issue 4824: Allow modules to implement generated source code to be shown in the standard SrcTab.

Added: trunk/src_new/org/argouml/application/api/Predicate.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/application/api/Predicate.java?view=auto&rev=13250
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/application/api/Predicate.java	2007-08-05 14:36:16-0700
@@ -0,0 +1,35 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $
+// Copyright (c) 2007 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.application.api;
+
+/**
+ * Defines a functor interface implemented by 
+ * classes that perform a predicate.
+ * 
+ * @author michiel
+ */
+public interface Predicate {
+    public boolean evaluate(Object object);
+}

Modified: trunk/src_new/org/argouml/uml/ui/TabSrc.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/ui/TabSrc.java?view=diff&rev=13250&p1=trunk/src_new/org/argouml/uml/ui/TabSrc.java&p2=trunk/src_new/org/argouml/uml/ui/TabSrc.java&r1=13249&r2=13250
==============================================================================
--- trunk/src_new/org/argouml/uml/ui/TabSrc.java	(original)
+++ trunk/src_new/org/argouml/uml/ui/TabSrc.java	2007-08-05 14:36:16-0700
@@ -26,11 +26,14 @@
 
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import javax.swing.JComboBox;
 
 import org.apache.log4j.Logger;
+import org.argouml.application.api.Predicate;
 import org.argouml.language.ui.LanguageComboBox;
 import org.argouml.model.Model;
 import org.argouml.ui.TabText;
@@ -43,7 +46,7 @@
 
 /**
  * Details panel tabbed panel for displaying a source code representation of
- * a UML model element in a particular Notation.
+ * a UML model element in a particular Language.
  */
 public class TabSrc
     extends TabText
@@ -59,16 +62,28 @@
 
     private LanguageComboBox cbLang = new LanguageComboBox();
     private JComboBox cbFiles = new JComboBox();
+    
+    /**
+     * This predicate determines if this tab is enabled.
+     */
+    private static List<Predicate> predicates;
 
     ////////////////////////////////////////////////////////////////
     // constructor
 
     /**
      * Create a tab that contains a toolbar.
-     * Then add a notation selector onto it.
+     * Then add a language selector onto it.
      */
     public TabSrc() {
         super("tab.source", true);
+        if (predicates == null) {
+            predicates = new ArrayList<Predicate>();
+            /* Add a predicate for ArgoUML's
+             * default capabilities: */
+            predicates.add(new DefaultPredicate());
+        }
+
         setEditable(false);
         langName = (Language) cbLang.getSelectedItem();
         fileName = null;
@@ -162,8 +177,10 @@
         target = (target instanceof Fig) ? ((Fig) target).getOwner() : target;
 
         setShouldBeEnabled(false);
-        if (Model.getFacade().isAClassifier(target)) {
-            setShouldBeEnabled(true);
+        for (Predicate p : predicates) {
+            if (p.evaluate(target)) {
+                setShouldBeEnabled(true);
+            }
         }
 
         return shouldBeEnabled();
@@ -199,5 +216,23 @@
         setTarget(getTarget());
     }
 
-
+    /**
+     * This function allows extra predicates to be added.
+     * The predicates are conditions for cases where the 
+     * TabSrc should show source code. If a plugin module 
+     * is able to generate code for certain objects, for
+     * which ArgoUML itself does not generate code, then
+     * this function will allow the module to show the tab.
+     *  
+     * @param predicate
+     */
+    public static void addPredicate(Predicate predicate) {
+        predicates.add(predicate);
+    }
+
+    class DefaultPredicate implements Predicate{
+        public boolean evaluate(Object object) {
+            return (Model.getFacade().isAClassifier(object));
+        }
+    }
 } /* end class TabSrc */
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.