On Thu, Jan 19, 2012 at 11:44 AM, Durchholz, Joachim
<joachim.durchh...@hennig-fahrzeugteile.de> wrote:
> Oh... you can write extensions to Modeler?
> Is there an official interface for that?

I don't think this made it into the official code.   It was part of
the tail-end of the last active Cayenne project I worked on before
politics changed that project from Cayenne to JPA.

I think I decided not to pursue it because (1) I wouldn't be around to
maintain it, and (2) there was already ongoing discussion about the
best way to allow modeler extensions.

The actual changes to allow extensions is pretty simple and small,
although "detecting" extensions in this version involves specifying an
"org.apache.cayenne.modeler.cayenneActionPluginFactory" System
property and including your extensions in the classpath.

But at the time, it worked well enough for my purposes.

I haven't followed the modeler development closely since then (2007?)
so I am not sure what, if any, extensions points currently exist.   My
guess is that it would be easy for you integrate this into the current
code base -- really, it's a quick easy hack to add menu items to
various modeler menus.


Index: 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/CayenneModelerFrame.java
===================================================================
--- 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/CayenneModelerFrame.java
      (revision
432015)
+++ 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/CayenneModelerFrame.java
      (working
copy)
@@ -60,6 +60,8 @@
 import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.event.KeyEvent;
+import java.util.Iterator;
+import java.util.List;

 import javax.swing.Box;
 import javax.swing.JFrame;
@@ -111,6 +113,8 @@
 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayListener;
 import org.objectstyle.cayenne.modeler.event.QueryDisplayEvent;
 import org.objectstyle.cayenne.modeler.event.QueryDisplayListener;
+import org.objectstyle.cayenne.modeler.plugin.CayenneActionPlugin;
+import org.objectstyle.cayenne.modeler.plugin.CayenneActionPluginManager;
 import org.objectstyle.cayenne.modeler.util.CayenneAction;
 import org.objectstyle.cayenne.modeler.util.RecentFileMenu;

@@ -209,6 +213,24 @@
         menuBar.add(fileMenu);
         menuBar.add(projectMenu);
         menuBar.add(toolMenu);
+
+        List cayennePluginActionList =
CayenneActionPluginManager.getInstance().getCayenneActionPluginList();
+        if (null != cayennePluginActionList)
+        {
+            JMenu pluginsMenu = new JMenu("Extensions");
+            if (!SystemUtils.IS_OS_MAC_OSX) {
+                pluginsMenu.setMnemonic(KeyEvent.VK_X);
+            }
+
+            Iterator cayennePluginActionIterator =
cayennePluginActionList.iterator();
+            while (cayennePluginActionIterator.hasNext()) {
+                CayenneActionPlugin cayennePluginAction =
(CayenneActionPlugin) cayennePluginActionIterator.next();
+
pluginsMenu.add(getAction(cayennePluginAction.getActionName()).buildMenu());
+            }
+
+            menuBar.add(pluginsMenu);
+        }
+
         menuBar.add(helpMenu);

         setJMenuBar(menuBar);
Index: 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/ActionManager.java
===================================================================
--- 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/ActionManager.java
    (revision
432015)
+++ 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/ActionManager.java
    (working
copy)
@@ -61,6 +61,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;

 import javax.swing.Action;
@@ -100,6 +101,8 @@
 import org.objectstyle.cayenne.modeler.action.SaveAction;
 import org.objectstyle.cayenne.modeler.action.SaveAsAction;
 import org.objectstyle.cayenne.modeler.action.ValidateAction;
+import org.objectstyle.cayenne.modeler.plugin.CayenneActionPlugin;
+import org.objectstyle.cayenne.modeler.plugin.CayenneActionPluginManager;
 import org.objectstyle.cayenne.modeler.util.CayenneAction;

 /**
@@ -167,6 +170,44 @@
     protected Map actionMap;

     public ActionManager(Application application) {
+
+        List cayennePluginActionList =
CayenneActionPluginManager.getInstance().getCayenneActionPluginList();
+        if (null != cayennePluginActionList)
+        {
+            Iterator cayennePluginActionIterator =
cayennePluginActionList.iterator();
+            while (cayennePluginActionIterator.hasNext()) {
+                CayenneActionPlugin cayennePluginAction =
(CayenneActionPlugin) cayennePluginActionIterator.next();
+                if (cayennePluginAction.isSpecialAction())
+                {
+                    SPECIAL_ACTIONS.add(cayennePluginAction.getActionName());
+                }
+                if (cayennePluginAction.isProjectAction())
+                {
+                    PROJECT_ACTIONS.add(cayennePluginAction.getActionName());
+                }
+                if (cayennePluginAction.isDomainAction())
+                {
+                    DOMAIN_ACTIONS.add(cayennePluginAction.getActionName());
+                }
+                if (cayennePluginAction.isDataMapAction())
+                {
+                    DATA_MAP_ACTIONS.add(cayennePluginAction.getActionName());
+                }
+                if (cayennePluginAction.isObjEntityAction())
+                {
+
OBJ_ENTITY_ACTIONS.add(cayennePluginAction.getActionName());
+                }
+                if (cayennePluginAction.isDbEntityAction())
+                {
+                    DB_ENTITY_ACTIONS.add(cayennePluginAction.getActionName());
+                }
+                if (cayennePluginAction.isProcedureAction())
+                {
+                    PROCEDURE_ACTIONS.add(cayennePluginAction.getActionName());
+                }
+            }
+        }
+
         this.actionMap = new HashMap();

         registerAction(new ProjectAction(application));
@@ -204,6 +245,16 @@
         registerAction(new ExitAction(application)).setAlwaysOn(true);
         registerAction(new
NavigateBackwardAction(application)).setAlwaysOn(true);
         registerAction(new
NavigateForwardAction(application)).setAlwaysOn(true);
+
+        if (null != cayennePluginActionList)
+        {
+            Iterator cayennePluginActionIterator =
cayennePluginActionList.iterator();
+            while (cayennePluginActionIterator.hasNext()) {
+                CayenneActionPlugin cayennePluginAction =
(CayenneActionPlugin) cayennePluginActionIterator.next();
+
registerAction(cayennePluginAction.createCayenneAction(application));
+            }
+        }
+
     }

     private CayenneAction registerAction(CayenneAction action) {
Index: 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPlugin.java
===================================================================
--- 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPlugin.java
       (revision
0)
+++ 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPlugin.java
       (revision
0)
@@ -0,0 +1,72 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ *    must include the following acknowlegement:
+ *    "This product includes software developed by independent contributors
+ *    and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, email
+ *    "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ *    or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ *    names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site.  For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.modeler.plugin;
+
+import org.objectstyle.cayenne.modeler.Application;
+import org.objectstyle.cayenne.modeler.util.CayenneAction;
+
+
+public interface CayenneActionPlugin {
+    public String getActionName();
+    public CayenneAction createCayenneAction(Application application);
+    public boolean isSpecialAction();
+    public boolean isProjectAction();
+    public boolean isDomainAction();
+    public boolean isDataMapAction();
+    public boolean isObjEntityAction();
+    public boolean isDbEntityAction();
+    public boolean isProcedureAction();
+}

Index: 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPluginFactory.java
===================================================================
--- 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPluginFactory.java
        (revision
0)
+++ 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPluginFactory.java
        (revision
0)
@@ -0,0 +1,63 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ *    must include the following acknowlegement:
+ *    "This product includes software developed by independent contributors
+ *    and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, email
+ *    "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ *    or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ *    names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site.  For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.modeler.plugin;
+
+import java.util.List;
+
+
+public interface CayenneActionPluginFactory {
+    public List getCayenneActionPluginList();
+}

Index: 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPluginManager.java
===================================================================
--- 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPluginManager.java
        (revision
0)
+++ 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/CayenneActionPluginManager.java
        (revision
0)
@@ -0,0 +1,111 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2006, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ *    must include the following acknowlegement:
+ *    "This product includes software developed by independent contributors
+ *    and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, email
+ *    "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ *    or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ *    names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site.  For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.modeler.plugin;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+public class CayenneActionPluginManager {
+
+    private static final Logger logObj =
Logger.getLogger(CayenneActionPluginManager.class);
+
+    private CayenneActionPluginFactory cayenneActionPluginFactory = null;
+    public CayenneActionPluginFactory getCayenneActionPluginFactory()
+    {
+        // TODO: retrieve somehow and allow multiple factories.
+        if (null == cayenneActionPluginFactory)
+        {
+            String pluginName =
System.getProperty("org.apache.cayenne.modeler.cayenneActionPluginFactory");
+            if (null != pluginName)
+            {
+                try {
+                    cayenneActionPluginFactory =
(CayenneActionPluginFactory)Class.forName(pluginName).newInstance();
+                }
+                catch (InstantiationException e) {
+                    logObj.error("InstantiationException error
instantiating cayenneActionPluginFactory", e);
+                }
+                catch (IllegalAccessException e) {
+                    logObj.error("IllegalAccessException error
instantiating cayenneActionPluginFactory", e);
+                }
+                catch (ClassNotFoundException e) {
+                    logObj.error("ClassNotFoundException error
instantiating cayenneActionPluginFactory", e);
+                }
+            }
+        }
+        return cayenneActionPluginFactory;
+    }
+
+    private static CayenneActionPluginManager instance = null;
+    public static CayenneActionPluginManager getInstance() {
+        if (null == instance)
+        {
+            instance = new CayenneActionPluginManager();
+        }
+        return instance;
+    }
+
+    public List getCayenneActionPluginList() {
+        CayenneActionPluginFactory cayenneActionPluginFactory =
getCayenneActionPluginFactory();
+        if (null != cayenneActionPluginFactory)
+        {
+            return
getCayenneActionPluginFactory().getCayenneActionPluginList();
+        }
+
+        return null;
+    }
+
+}
\ No newline at end of file

Index: 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/BaseCayenneActionPlugin.java
===================================================================
--- 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/BaseCayenneActionPlugin.java
   (revision
0)
+++ 
E:/workspace311/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/plugin/BaseCayenneActionPlugin.java
   (revision
0)
@@ -0,0 +1,34 @@
+package org.objectstyle.cayenne.modeler.plugin;
+
+import org.objectstyle.cayenne.modeler.Application;
+import org.objectstyle.cayenne.modeler.plugin.CayenneActionPlugin;
+import org.objectstyle.cayenne.modeler.util.CayenneAction;
+
+abstract public class BaseCayenneActionPlugin implements CayenneActionPlugin {
+
+    abstract public String getActionName();
+    abstract public CayenneAction createCayenneAction(Application application);
+
+    public boolean isSpecialAction() {
+        return false;
+    }
+    public boolean isProjectAction() {
+        return false;
+    }
+    public boolean isDomainAction() {
+        return false;
+    }
+    public boolean isDataMapAction() {
+        return false;
+    }
+    public boolean isObjEntityAction() {
+        return false;
+    }
+    public boolean isDbEntityAction() {
+        return false;
+    }
+    public boolean isProcedureAction() {
+        return false;
+    }
+
+}

Reply via email to