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;
/**
* Application settings logger.
*/
- protected final static Logger LOG = Logger
+ protected final static AppLogger LOG = AppLogger
.getLogger(ApplicationSettings.class);
/**
* JNDI context for launching converters.
* 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.
*/
/**
* 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.
*/
* 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.
*/
*/
edit,
/**
- * script
+ * script.
*/
script,
/**
*/
version,
/**
- * replace
+ * replace.
*/
replace,
/**
- * export
+ * export.
*/
export,
/**
*/
remove,
/**
- * purge
+ * purge.
*/
purge,
/**
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();
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) {
// 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;
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;
}
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.
*/
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(
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"));
/**
* 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(
"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)
}
/**
- * 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)
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)
"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);
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) {
}
// 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)
"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) {
// Public member functions
// ==============================================================================================================================
+ /**
+ * Initialize application menus.
+ */
public void configure() {
// Non customizable settings
_menus.clear();
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<PopupItem> 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<PopupItem> 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