From 386f2a1fb669b7c8784f5782b630ab2ab6ca2107 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Sat, 21 Jun 2003 03:24:42 +0000 Subject: [PATCH] added high-level "macro" classes for modules to use to install menu entries --- conf/venice-db-init-mysql.sql | 11 ++ .../venice/iface/MenuEditObject.java | 2 + .../silverwrist/venice/menu/MenuEditImpl.java | 9 ++ .../venice/menu/MenuEditItemImpl.java | 6 + .../venice/util/CommunityMenuInstaller.java | 137 ++++++++++++++++++ .../venice/util/SystemAdminMenuInstaller.java | 97 +++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 src/venice-base/com/silverwrist/venice/util/CommunityMenuInstaller.java create mode 100644 src/venice-base/com/silverwrist/venice/util/SystemAdminMenuInstaller.java diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index 2b66656..00a0a8d 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -1465,6 +1465,17 @@ INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link, perm_ns (9, 65000, 'MARKER', 'end-module-sysadmin', NULL, NULL, NULL, NULL ); +# Create the community service admin menu. (ID #10) +INSERT INTO menus (menuid, menu_nsid, menu_name, title, subtitle) + VALUES (10, 16, 'community.admin.service', 'Manage Community Services:', '${name}'); +INSERT INTO menuvars (menuid, var_name, default_val) VALUES + (10, 'name', NULL), + (10, 'cid', NULL); +INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link, perm_nsid, perm_name) VALUES + (10, 0, 'TEXT', 'Return to Previous Menu', 'SERVLET', 'comm/admin/main.js?cc=${cid}', NULL, NULL), + (10, 100, 'MARKER', 'begin-service-admin', NULL, NULL, NULL, NULL), + (10, 65000, 'MARKER', 'end-service-admin', NULL, NULL, NULL, NULL); + # Create the sideboxes tables. INSERT INTO sbox_master (sbid, sb_nsid, sb_name, type_nsid, type_name, descr) VALUES (1, 19, 'community.list', 19, 'community.list', 'Community Membership List'), diff --git a/src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java b/src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java index 9ad2812..bc91f19 100644 --- a/src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java +++ b/src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java @@ -48,6 +48,8 @@ public interface MenuEditObject public MenuEditItemObject getItemByTypeText(String type, String text); + public MenuEditItemObject getItemContainingLinkText(String text); + public MenuEditItemObject getNextItem(MenuEditItemObject obj); public MenuEditItemObject getPreviousItem(MenuEditItemObject obj); diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java b/src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java index 11a082d..8c6a0de 100644 --- a/src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java +++ b/src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java @@ -164,6 +164,15 @@ class MenuEditImpl implements MenuEditObject } // end getItemByTypeText + public MenuEditItemObject getItemContainingLinkText(String text) + { + if (m_mdef==null) + return null; + int ndx = m_mdef.getItemContainingLinkText(text); + return (ndx<0) ? null : this.getItem(ndx); + + } // end getItemContainingLinkText + public MenuEditItemObject getNextItem(MenuEditItemObject obj) { return this.getItem(obj.getIndexOfItem() + 1); diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java b/src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java index 579cd3d..d90aecf 100644 --- a/src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java +++ b/src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java @@ -91,6 +91,8 @@ class MenuEditItemImpl implements MenuEditItemObject public void setSequence(int seq) throws DatabaseException { baleeted(); + if (m_item.getSequence()==seq) + return; m_ops.setItemSequence(m_mdef.getID(),m_item.getSequence(),seq); m_item.setSequence(seq); m_mdef.resequence(); @@ -106,6 +108,8 @@ class MenuEditItemImpl implements MenuEditItemObject public void setEnabled(boolean flag) throws DatabaseException { baleeted(); + if (m_item.isEnabled()==flag) + return; m_ops.setItemEnable(m_mdef.getID(),m_item.getSequence(),flag); m_item.setEnabled(flag); @@ -122,6 +126,8 @@ class MenuEditItemImpl implements MenuEditItemObject baleeted(); if (indent<0) throw new IllegalArgumentException("indent must be >= 0"); + if (indent==m_item.getIndentLevel()) + return; m_ops.setItemIndent(m_mdef.getID(),m_item.getSequence(),indent); m_item.setIndentLevel(indent); diff --git a/src/venice-base/com/silverwrist/venice/util/CommunityMenuInstaller.java b/src/venice-base/com/silverwrist/venice/util/CommunityMenuInstaller.java new file mode 100644 index 0000000..5f7a9ab --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/util/CommunityMenuInstaller.java @@ -0,0 +1,137 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.util; + +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.venice.VeniceNamespaces; +import com.silverwrist.venice.iface.*; + +public class CommunityMenuInstaller +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static final int STD_GAP = 100; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private MenuProvider m_provider; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + CommunityMenuInstaller(ServiceProvider services) + { + m_provider = (MenuProvider)(services.queryService(MenuProvider.class)); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public void installCommunityServiceEntry(DynamoUser caller, String text, String linktype, String link, + String shortvar) throws DatabaseException, DynamoSecurityException + { + MenuEditObject menu = m_provider.getEditMenu(caller,VeniceNamespaces.COMMUNITY_GLOBALS_NAMESPACE,"community.menu"); + MenuEditItemObject end_marker = menu.getItemByTypeText("MARKER","end-services"); + MenuEditItemObject insert_after = menu.getPreviousItem(end_marker); + int new_sequence = insert_after.getSequence() + STD_GAP; + if (new_sequence>=end_marker.getSequence()) + { // need to renumber the menu items + MenuEditItemObject item = menu.getItemByTypeText("MARKER","begin-services"); + new_sequence = item.getSequence(); + item = menu.getNextItem(item); + new_sequence += STD_GAP; + while (!(item.getItemType().equals("MARKER"))) + { // reset the numbers for the sequence + item.setSequence(new_sequence); + item = menu.getNextItem(item); + new_sequence += STD_GAP; + + } // end while + + } // end if + + MenuEditItemObject new_object = menu.addItem("TEXT",new_sequence,text,linktype,link); + new_object.setIfDefVar(shortvar); + + } // end installCommunityServiceEntry + + public void removeCommunityServiceEntry(DynamoUser caller, String link_text) + throws DatabaseException, DynamoSecurityException + { + MenuEditObject menu = m_provider.getEditMenu(caller,VeniceNamespaces.COMMUNITY_GLOBALS_NAMESPACE,"community.menu"); + MenuEditItemObject item = menu.getItemContainingLinkText(link_text); + if (item!=null) + item.delete(); + + } // end removeCommunityServiceEntry + + public void installCommunityServiceAdminEntry(DynamoUser caller, String text, String linktype, String link, + String perm_nsid, String perm_name, String shortvar) + throws DatabaseException, DynamoSecurityException + { + MenuEditObject menu = m_provider.getEditMenu(caller,VeniceNamespaces.COMMUNITY_GLOBALS_NAMESPACE, + "community.admin.service"); + MenuEditItemObject end_marker = menu.getItemByTypeText("MARKER","end-service-admin"); + MenuEditItemObject insert_after = menu.getPreviousItem(end_marker); + int new_sequence = insert_after.getSequence() + STD_GAP; + if (new_sequence>=end_marker.getSequence()) + { // need to renumber the menu items + MenuEditItemObject item = menu.getItemByTypeText("MARKER","begin-service-admin"); + new_sequence = item.getSequence(); + item = menu.getNextItem(item); + new_sequence += STD_GAP; + while (!(item.getItemType().equals("MARKER"))) + { // reset the numbers for the sequence + item.setSequence(new_sequence); + item = menu.getNextItem(item); + new_sequence += STD_GAP; + + } // end while + + } // end if + + MenuEditItemObject new_object = menu.addItem("TEXT",new_sequence,text,linktype,link); + new_object.setPermission(perm_nsid,perm_name); + new_object.setIfDefVar(shortvar); + + } // end installCommunityServiceAdminEntry + + public void removeCommunityServiceAdminEntry(DynamoUser caller, String link_text) + throws DatabaseException, DynamoSecurityException + { + MenuEditObject menu = m_provider.getEditMenu(caller,VeniceNamespaces.COMMUNITY_GLOBALS_NAMESPACE, + "community.admin.service"); + MenuEditItemObject item = menu.getItemContainingLinkText(link_text); + if (item!=null) + item.delete(); + + } // end removeCommunityServiceAdminEntry + +} // end class CommunityMenuInstaller diff --git a/src/venice-base/com/silverwrist/venice/util/SystemAdminMenuInstaller.java b/src/venice-base/com/silverwrist/venice/util/SystemAdminMenuInstaller.java new file mode 100644 index 0000000..1d6b464 --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/util/SystemAdminMenuInstaller.java @@ -0,0 +1,97 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.util; + +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.venice.VeniceNamespaces; +import com.silverwrist.venice.iface.*; + +public class SystemAdminMenuInstaller +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static final int STD_GAP = 100; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private MenuProvider m_provider; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + SystemAdminMenuInstaller(ServiceProvider services) + { + m_provider = (MenuProvider)(services.queryService(MenuProvider.class)); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public void installSystemAdminEntry(DynamoUser caller, String text, String linktype, String link, String perm_nsid, + String perm_name) throws DatabaseException, DynamoSecurityException + { + MenuEditObject menu = m_provider.getEditMenu(caller,VeniceNamespaces.SYSTEM_PERMS_NAMESPACE, + "system.admin.module"); + MenuEditItemObject end_marker = menu.getItemByTypeText("MARKER","end-module-sysadmin"); + MenuEditItemObject insert_after = menu.getPreviousItem(end_marker); + int new_sequence = insert_after.getSequence() + STD_GAP; + if (new_sequence>=end_marker.getSequence()) + { // need to renumber the menu items + MenuEditItemObject item = menu.getItemByTypeText("MARKER","begin-module-sysadmin"); + new_sequence = item.getSequence(); + item = menu.getNextItem(item); + new_sequence += STD_GAP; + while (!(item.getItemType().equals("MARKER"))) + { // reset the numbers for the sequence + item.setSequence(new_sequence); + item = menu.getNextItem(item); + new_sequence += STD_GAP; + + } // end while + + } // end if + + MenuEditItemObject new_object = menu.addItem("TEXT",new_sequence,text,linktype,link); + new_object.setPermission(perm_nsid,perm_name); + + } // end installSystemAdminEntry + + public void removeSystemAdminEntry(DynamoUser caller, String link_text) + throws DatabaseException, DynamoSecurityException + { + MenuEditObject menu = m_provider.getEditMenu(caller,VeniceNamespaces.SYSTEM_PERMS_NAMESPACE, + "system.admin.module"); + MenuEditItemObject item = menu.getItemContainingLinkText(link_text); + if (item!=null) + item.delete(); + + } // end removeSystemAdminEntry + +} // end class SystemAdminMenuInstaller