Salome HOME
Fix of "Remove this version" menu item. Also Logger is replaced by AppLogger.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / ApplicationSettings.java
index a30dd31f205cb74a73566486b633d84d1eee7cbd..6fb1c238eb52d1491f7ab0d385370184facfbb9d 100644 (file)
@@ -16,14 +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.ProgressState;
 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;
@@ -49,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.
@@ -177,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.
         */
@@ -229,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.
         */
@@ -250,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.
         */
@@ -475,7 +474,7 @@ public class ApplicationSettings {
                 */
                edit,
                /**
-                * script
+                * script.
                 */
                script,
                /**
@@ -483,11 +482,11 @@ public class ApplicationSettings {
                 */
                version,
                /**
-                * replace
+                * replace.
                 */
                replace,
                /**
-                * export
+                * export.
                 */
                export,
                /**
@@ -495,7 +494,7 @@ public class ApplicationSettings {
                 */
                remove,
                /**
-                * purge
+                * purge.
                 */
                purge,
                /**
@@ -600,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();
@@ -617,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) {
@@ -634,45 +638,19 @@ 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);
@@ -691,17 +669,29 @@ 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 remove:
+                                               res = _user.canRemove();
+                                               break;
                                        case purge:
                                                res = _user.canPurge();
                                                break;
-                                       case remove:
-                                               res = _user.canRemove();
+                                       case undo:
+                                               res = _user.canInvalidate();
+                                               break;
+                                       case demote:
+                                               res = _user.canDemote();
+                                               break;
+                                       case approve:
+                                               res = _user.canApprove();
                                                break;
                                        default:
                                                res = false;
@@ -710,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.
                 */
@@ -752,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(
@@ -808,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"));
@@ -820,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(
@@ -836,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)
@@ -882,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)
@@ -903,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)
@@ -953,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);
@@ -967,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) {
@@ -978,18 +937,21 @@ 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_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
-                                       "image.review.png").action("promote-knowledge")
-                                       .confirmation("message.promote.knowledge"));
-                       addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
-                                       "image.invalidate.png").action("demote-knowledge")
-                                       .confirmation("message.demote.knowledge"));
-                       addSeparator();
                        addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
                                        .action("edit-knowledge?action=renameKnowledge"));
                        addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
@@ -1000,22 +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) {
-                       Item item = Item.valueOf(name);
                        boolean res = true;
-
-                       if (item == Item.promote) {
-                               if (_owner.getProgressState() != ProgressState.inDRAFT) {
-                                       res = false;
-                               }
-                       } else if ((item == Item.demote)
-                                       && (_owner.getProgressState() != ProgressState.inCHECK)) {
-                               res = false;
-                       }
                        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) {
@@ -1092,6 +1054,9 @@ public class ApplicationSettings {
        // Public member functions
        // ==============================================================================================================================
 
+       /**
+        * Initialize application menus.
+        */
        public void configure() {
                // Non customizable settings
                _menus.clear();