From: rkv Date: Tue, 9 Apr 2013 07:50:52 +0000 (+0000) Subject: Fix of "Remove this version" menu item. Also Logger is replaced by AppLogger. X-Git-Tag: Root_Delivery2_2013_04_22~45 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2edb0d9244ce3b60c81ff6e7400257257f98f4e8;hp=9f5dffbe22d3af15b4b6c6196d137f6429a94d97;p=tools%2Fsiman.git Fix of "Remove this version" menu item. Also Logger is replaced by AppLogger. --- diff --git a/Workspace/Siman/src/org/splat/simer/Action.java b/Workspace/Siman/src/org/splat/simer/Action.java index 6dabea0..b0ebfa5 100644 --- a/Workspace/Siman/src/org/splat/simer/Action.java +++ b/Workspace/Siman/src/org/splat/simer/Action.java @@ -7,13 +7,13 @@ import java.util.ResourceBundle; import javax.security.auth.login.LoginContext; import javax.servlet.http.HttpServletRequest; -import org.apache.log4j.Logger; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.SessionAware; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; +import org.splat.log.AppLogger; import org.splat.service.dto.KnowledgeElementDTO; import org.splat.som.ApplicationRights; import org.splat.som.StudyRights; @@ -35,7 +35,7 @@ public class Action extends ActionSupport implements ServletRequestAware, /** * Action logger. */ - protected static final Logger LOG = Logger.getLogger(Action.class); + protected static final AppLogger LOG = AppLogger.getLogger(Action.class); /** * Open knowledge key in session. diff --git a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java index d1f9c55..6fb1c23 100644 --- a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java +++ b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java @@ -16,13 +16,13 @@ import javax.servlet.http.HttpServletRequest; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.apache.log4j.Logger; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Visibility; +import org.splat.log.AppLogger; import org.splat.manox.XDOM; import org.splat.service.DocumentTypeService; import org.splat.service.technical.ProjectSettingsService; @@ -48,7 +48,7 @@ public class ApplicationSettings { /** * Application settings logger. */ - protected final static Logger LOG = Logger + protected final static AppLogger LOG = AppLogger .getLogger(ApplicationSettings.class); /** * JNDI context for launching converters. @@ -176,10 +176,10 @@ public class ApplicationSettings { * Version menu item name. */ private static final String MNU_VERSION = "version"; - /** - * Purge menu item name. - */ - private static final String MNU_PURGE = "purge"; + // /** + // * Purge menu item name. + // */ + // private static final String MNU_PURGE = "purge"; /** * Remove menu item name. */ @@ -228,7 +228,7 @@ public class ApplicationSettings { /** * Purge menu item name. */ - //private static final String MNU_NAME_PURGE = "menu.purge"; + // private static final String MNU_NAME_PURGE = "menu.purge"; /** * Remove menu item name. */ @@ -249,10 +249,10 @@ public class ApplicationSettings { * Remove as reference menu item label key. */ private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference"; - /** - * Not yet implemented action name. - */ - private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented"; + // /** + // * Not yet implemented action name. + // */ + // private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented"; /** * Attach action name. */ @@ -474,7 +474,7 @@ public class ApplicationSettings { */ edit, /** - * script + * script. */ script, /** @@ -482,11 +482,11 @@ public class ApplicationSettings { */ version, /** - * replace + * replace. */ replace, /** - * export + * export. */ export, /** @@ -494,7 +494,7 @@ public class ApplicationSettings { */ remove, /** - * purge + * purge. */ purge, /** @@ -599,9 +599,9 @@ public class ApplicationSettings { case remove: res = _user.canRemove(); break; - /*case purge: - res = _user.canPurge(); - break;*/ + /* + * case purge: res = _user.canPurge(); break; + */ case markasreference: if (_user.getOperand().getMarkreference() == 0) { res = _user.canMarkStudyAsReference(); @@ -616,6 +616,11 @@ public class ApplicationSettings { return res; } + /** + * {@inheritDoc} + * + * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object) + */ @Override public void setContext(final String name, final Object context) { if (context instanceof StudyRights) { @@ -633,54 +638,28 @@ public class ApplicationSettings { // Resources relative to documents /** - * Popup of In-Work documents. + * Popup of a document. */ - private static class EditableDocumentPopup extends PopupMenu { + private static class DocumentPopup extends PopupMenu { /** - * User rights for the selected document. + * Current user rights. */ private transient DocumentRights _user = null; /** - * Document popup menu constructor. + * {@inheritDoc} + * + * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String) */ - private EditableDocumentPopup() { - super(); - /*addItem("accept", new PopupItem("menu.accept").icon( - "image.accept.png").action("setDocument?action=accept") - .confirmation("message.accept.document"));*/ - addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon( - "image.publish.png").action("setDocument?action=promote") - .confirmation("message.promote.document")); - addSeparator(); - addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) - .action("edit-document?action=renameDocument")); - addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) - .action(ACT_ATTACH)); - addSeparator(); - addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( - IMG_VERSION).action(ACT_VERSION)); - addItem("replace", new PopupItem("menu.replace").icon( - "image.replace.png").action( - "select-file?nextAction=replace")); - addSeparator(); - /*addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( - ACT_NOT_YET_IMPLEMENTED).confirmation( - "message.purge.document"));*/ - addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon( - IMG_DELETE).action("remove-document").confirmation( - "message.delete.document")); - } - @Override public boolean isEnabled(final String name) { boolean res = (_user != null); if (res) { Item item = Item.valueOf(name); switch (item) { - /*case accept: + case accept: res = _user.canAccept(); - break;*/ + break; case promote: res = _user.canPromote(); break; @@ -690,18 +669,30 @@ public class ApplicationSettings { case attach: res = _user.canAttach(); break; + case edit: + res = _user.canEdit(); + break; case version: res = _user.canVersion(); break; case replace: res = _user.canReplace(); break; - /*case purge: - res = _user.canPurge(); - break;*/ case remove: res = _user.canRemove(); break; + case purge: + res = _user.canPurge(); + break; + case undo: + res = _user.canInvalidate(); + break; + case demote: + res = _user.canDemote(); + break; + case approve: + res = _user.canApprove(); + break; default: res = false; } @@ -709,30 +700,68 @@ public class ApplicationSettings { return res; } + /** + * {@inheritDoc} + * + * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object) + */ @Override public void setContext(final String name, final Object context) { if (context instanceof DocumentRights) { _user = (DocumentRights) context; // Just for optimizing Document downer = _user.getOperand(); - PopupItem item = this.item(MNU_REMOVE); - if (downer.isVersioned()) { - item.rename(MNU_NAME_REMOVE_VERSION); - } else { - item.rename("menu.remove.document"); + if (this.hasItem(MNU_REMOVE)) { + if (downer.getPreviousVersion() == null) { + this.item(MNU_REMOVE).rename("menu.remove.document"); + } else { + this.item(MNU_REMOVE).rename(MNU_NAME_REMOVE_VERSION); + } } } } } /** - * Popup of In-Draft documents. + * Popup of In-Work documents. */ - private static class ReviewableDocumentPopup extends PopupMenu { + private static class EditableDocumentPopup extends DocumentPopup { /** - * User rights for the selected document. + * Document popup menu constructor. */ - private transient DocumentRights _user = null; + private EditableDocumentPopup() { + super(); + /* + * addItem("accept", new PopupItem("menu.accept").icon( "image.accept.png").action("setDocument?action=accept") + * .confirmation("message.accept.document")); + */ + addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon( + "image.publish.png").action("setDocument?action=promote") + .confirmation("message.promote.document")); + addSeparator(); + addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) + .action("edit-document?action=renameDocument")); + addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) + .action(ACT_ATTACH)); + addSeparator(); + addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( + IMG_VERSION).action(ACT_VERSION)); + addItem("replace", new PopupItem("menu.replace").icon( + "image.replace.png").action( + "select-file?nextAction=replace")); + addSeparator(); + /* + * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document")); + */ + addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon( + IMG_DELETE).action("remove-document").confirmation( + "message.delete.document")); + } + } + /** + * Popup of In-Draft documents. + */ + private static class ReviewableDocumentPopup extends DocumentPopup { /** * Document popup menu constructor. */ @@ -751,50 +780,19 @@ public class ApplicationSettings { addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_VERSION)); addSeparator(); - /*addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( - ACT_NOT_YET_IMPLEMENTED).confirmation( - "message.purge.document"));*/ - } - - @Override - public boolean isEnabled(final String name) { - boolean res = (_user != null); - if (res) { - Item item = Item.valueOf(name); - switch (item) { - case demote: - res = _user.canDemote(); - break; - case promote: - res = _user.canReview(); - break; - case attach: - res = _user.canAttach(); - break; - case version: - res = _user.canVersion(); - break; - /*case purge: - res = _user.canPurge(); - break;*/ - default: - res = false; - } - } - return res; - } - - @Override - public void setContext(final String name, final Object context) { - if (context instanceof DocumentRights) { - _user = (DocumentRights) context; // Just for optimizing - } + /* + * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document")); + */ } } - private static class NotResultDocumentPopup extends PopupMenu { - // private final DocumentRights _user = null; - + /** + * Popup menu for documents which are not results of a step. + */ + private static class NotResultDocumentPopup extends DocumentPopup { + /** + * Default constructor. + */ private NotResultDocumentPopup() { super(); addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon( @@ -807,9 +805,9 @@ public class ApplicationSettings { addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_VERSION)); addSeparator(); - /*addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( - ACT_NOT_YET_IMPLEMENTED).confirmation( - "message.purge.document"));*/ + /* + * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document")); + */ addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon( IMG_DELETE).action("remove-document").confirmation( "message.delete.document")); @@ -819,9 +817,10 @@ public class ApplicationSettings { /** * Popup of In-Check documents. */ - private static class ApprovableDocumentPopup extends PopupMenu { - private transient DocumentRights _user = null; - + private static class ApprovableDocumentPopup extends DocumentPopup { + /** + * Default constructor. + */ private ApprovableDocumentPopup() { super(); addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon( @@ -835,41 +834,15 @@ public class ApplicationSettings { "icon.APPROVED.png").action("setDocument?action=approve") .confirmation("message.approve.document")); } - - @Override - public boolean isEnabled(final String name) { - boolean res = (_user != null); - if (res) { - Item item = Item.valueOf(name); - switch (item) { - case undo: - res = _user.canInvalidate(); - break; - case demote: - res = _user.canDemote(); - break; - case approve: - res = _user.canApprove(); - break; - default: - res = false; - } - } - return res; - } - - @Override - public void setContext(final String name, final Object context) { - if (context instanceof DocumentRights) { - _user = (DocumentRights) context; // Just for optimizing - } - } } /** * Popup of Approved documents. */ - private static class ApprovedPopup extends PopupMenu { + private static class ApprovedPopup extends DocumentPopup { + /** + * Default constructor. + */ private ApprovedPopup() { super(); addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) @@ -881,11 +854,12 @@ public class ApplicationSettings { } /** - * Popup of Extern documents. + * Popup of external documents. */ - private static class ExternPopup extends PopupMenu { - private transient DocumentRights _user = null; - + private static class ExternPopup extends DocumentPopup { + /** + * Default constructor. + */ private ExternPopup() { super(); addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) @@ -902,44 +876,20 @@ public class ApplicationSettings { IMG_DELETE).action("remove-document").confirmation( "message.delete.document")); } - - @Override - public boolean isEnabled(final String name) { - boolean res = (_user != null); - if (res) { - Item item = Item.valueOf(name); - switch (item) { - case rename: - res = _user.canRename(); - break; - case version: - res = _user.canVersion(); - break; - case replace: - res = _user.canReplace(); - break; - case remove: - res = _user.canRemove(); - break; - default: - res = false; - } - } - return res; - } - - @Override - public void setContext(final String name, final Object context) { - if (context instanceof DocumentRights) { - _user = (DocumentRights) context; // Just for optimizing - } - } } - // Resources relative to simulation contexts + /** + * Simulation context popup menu. + */ private static class ScontextPopup extends PopupMenu { + /** + * Owner object. + */ private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it. + /** + * Default constructor. + */ private ScontextPopup() { super(); addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) @@ -952,6 +902,11 @@ public class ApplicationSettings { "message.delete.context")); } + /** + * {@inheritDoc} + * + * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String) + */ @Override public boolean isEnabled(final String name) { Item item = Item.valueOf(name); @@ -966,6 +921,11 @@ public class ApplicationSettings { return res; } + /** + * {@inheritDoc} + * + * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object) + */ @Override public void setContext(final String name, final Object context) { if (context instanceof SimulationContextFacade) { @@ -977,9 +937,19 @@ public class ApplicationSettings { } // Resources relative to knowledge + /** + * Knowledge element popup menu. + */ private static class FeedbexPopup extends PopupMenu { - private transient KnowledgeElement _owner = null; + /** + * Popup menu owner object. + */ + protected transient KnowledgeElement _owner = null; + + /** + * Default constructor. + */ private FeedbexPopup() { super(); addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) @@ -992,12 +962,22 @@ public class ApplicationSettings { "message.delete.knowledge")); } + /** + * {@inheritDoc} + * + * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String) + */ @Override public boolean isEnabled(final String name) { boolean res = true; return res; } + /** + * {@inheritDoc} + * + * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object) + */ @Override public void setContext(final String name, final Object context) { if (context instanceof KnowledgeElement) { @@ -1074,6 +1054,9 @@ public class ApplicationSettings { // Public member functions // ============================================================================================================================== + /** + * Initialize application menus. + */ public void configure() { // Non customizable settings _menus.clear(); diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 6b467ae..420ac86 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -14,7 +14,6 @@ import java.util.Iterator; import java.util.List; import java.util.ResourceBundle; -import org.apache.log4j.Logger; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.DocumentType; @@ -25,6 +24,7 @@ import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; import org.splat.kernel.Do; +import org.splat.log.AppLogger; import org.splat.manox.Toolbox; import org.splat.manox.Writer; import org.splat.service.DocumentService; @@ -49,7 +49,7 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { /** * Serial version ID. */ - protected final static Logger LOGGER = org.splat.simer.Action.LOG; + protected final static AppLogger LOGGER = org.splat.simer.Action.LOG; /** * The currently open study. diff --git a/Workspace/Siman/src/org/splat/wapp/PopupMenu.java b/Workspace/Siman/src/org/splat/wapp/PopupMenu.java index 2a7934a..734719e 100644 --- a/Workspace/Siman/src/org/splat/wapp/PopupMenu.java +++ b/Workspace/Siman/src/org/splat/wapp/PopupMenu.java @@ -2,48 +2,83 @@ package org.splat.wapp; import java.util.List; - +/** + * Base popup menu class. + */ public class PopupMenu extends ContextualMenu { -// ============================================================================================================================== -// Constructor -// ============================================================================================================================== - - public PopupMenu () { -// ------------------- - _width = 186; // Includes borders (2px) and shadow (4px) - _height = 2; // Top and bottom border - } - -// ============================================================================================================================== -// Member functions -// ============================================================================================================================== - - public void addItem (String name, PopupItem item) { -// ------------------------------------------------- - item._width = 180; - item._height = 22; // Height of image.selected.png background image - this._height += item._height; - super.addItem(name, item); - } - - public void addSeparator () { -// --------------------------- - PopupItem item = new PopupItem(); - item._width = 180; - item._height = 8; - this._height += item._height; - super.addItem("", item); - } - - @SuppressWarnings({"rawtypes","unchecked"}) - public List asList () { -// -------------------------------- - return (List)_items; - } - - public PopupItem item (String name) { -// ----------------------------------- - return (PopupItem)_items.get(_indices.get(name)); - } + // ============================================================================================================================== + // Constructor + // ============================================================================================================================== + + /** + * Default constructor. + */ + public PopupMenu() { + super(); + _width = 186; // Includes borders (2px) and shadow (4px) + _height = 2; // Top and bottom border + } + + // ============================================================================================================================== + // Member functions + // ============================================================================================================================== + + /** + * Add a menu item. + * + * @param name + * the item name + * @param item + * the item to add + */ + public void addItem(final String name, final PopupItem item) { + item._width = 180; + item._height = 22; // Height of image.selected.png background image + this._height += item._height; + super.addItem(name, item); + } + + /** + * Insert an items separator into the menu. + */ + public void addSeparator() { + PopupItem item = new PopupItem(); + item._width = 180; + item._height = 8; + this._height += item._height; + super.addItem("", item); + } + + /** + * Get the menu as a list of menu items. + * + * @return the list of menu items + */ + @SuppressWarnings(Constants.UNCHECKED) + public List asList() { + return (List) _items; + } + + /** + * Get menu item by name. + * + * @param name + * the menu item name + * @return the menu item + */ + public PopupItem item(final String name) { + return (PopupItem) _items.get(_indices.get(name)); + } + + /** + * Check if this menu contains the given item. + * + * @param name + * the item name + * @return true if this menu contains the given item. + */ + public boolean hasItem(final String name) { + return _indices.containsKey(name); + } } \ No newline at end of file