From 60ed5247281e24d48744b5c0c4a531827a57850b Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 17 Oct 2012 12:50:09 +0000 Subject: [PATCH] Addition of a new scenario to a study is fixed. StudyMenu and NewScenarioMenu are now session beans. --- .../org/splat/simer/NewScenarioAction.java | 20 +- .../src/org/splat/simer/NewScenarioMenu.java | 11 + .../Siman/src/org/splat/simer/OpenObject.java | 8 + .../Siman/src/org/splat/simer/OpenStudy.java | 6 +- .../Siman/src/org/splat/simer/StudyMenu.java | 423 ++++++++++-------- Workspace/Siman/src/org/splat/wapp/Menu.java | 11 +- .../Siman/src/spring/applicationContext.xml | 31 +- 7 files changed, 306 insertions(+), 204 deletions(-) diff --git a/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java b/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java index 85adabd..9ff3ed6 100644 --- a/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java +++ b/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java @@ -29,6 +29,7 @@ public class NewScenarioAction extends Action { private ToDo action; private StudyService _studyService; private ProjectElementService _projectElementService; + private Menu _menu; /** * Serial version ID. @@ -56,7 +57,8 @@ public class NewScenarioAction extends Action { selection = scindex + "." + bastep; action = null; - Menu menu = new NewScenarioMenu(study); +//RKV Menu menu = new NewScenarioMenu(study); + Menu menu = ((NewScenarioMenu)getMenu()).init(study); //RKV menu.selects(selection); getSession().put("menu.scenario", menu); return SUCCESS; @@ -219,4 +221,20 @@ public class NewScenarioAction extends Action { ProjectElementService projectElementService) { _projectElementService = projectElementService; } + + /** + * Get the menu. + * @return the menu + */ + public Menu getMenu() { + return _menu; + } + + /** + * Set the menu. + * @param menu the menu to set + */ + public void setMenu(Menu menu) { + _menu = menu; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/NewScenarioMenu.java b/Workspace/Siman/src/org/splat/simer/NewScenarioMenu.java index a741099..7fcc9e4 100644 --- a/Workspace/Siman/src/org/splat/simer/NewScenarioMenu.java +++ b/Workspace/Siman/src/org/splat/simer/NewScenarioMenu.java @@ -23,6 +23,17 @@ public class NewScenarioMenu extends SlidMenu { // Constructor // ============================================================================================================================== + public NewScenarioMenu() { + super("scenarii", "study"); + scopen = null; + } + + public NewScenarioMenu init(Study context) { + study = context; + scopen = null; + return this; + } + public NewScenarioMenu(Study context) { // ----------------------------------- super("scenarii", "study"); diff --git a/Workspace/Siman/src/org/splat/simer/OpenObject.java b/Workspace/Siman/src/org/splat/simer/OpenObject.java index 465b4fc..ce6bc8c 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenObject.java +++ b/Workspace/Siman/src/org/splat/simer/OpenObject.java @@ -302,4 +302,12 @@ public abstract class OpenObject implements Proxy { public void setPublicationService(PublicationService publicationService) { _publicationService = publicationService; } + + /** + * Set the menu. + * @param menu the menu to set + */ + public void setMenu(Menu menu) { + this.menu = menu; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 0e19bf0..8f0b58f 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -38,6 +38,7 @@ import org.splat.som.Step; import org.splat.som.StepRights; import org.splat.dal.bo.som.Study; import org.splat.som.StudyRights; +import org.splat.wapp.Menu; import org.splat.wapp.ToolBar; @@ -115,7 +116,8 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { urightstudy = new StudyRights(cuser, mystudy); urightstep = new StepRights(cuser, ustep); - menu = new StudyMenu(mystudy); +//RKV menu = new StudyMenu(mystudy); + menu = ((StudyMenu)getMenu()).init(mystudy); //RKV ((StudyMenu)menu).setProjectElementService(getProjectElementService()); ((StudyMenu)menu).setScenarioService(getScenarioService()); menu.selects(selection); // Initializes menu items to be displayed @@ -127,7 +129,7 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { // Getters // ============================================================================================================================== - public String getAuthorName() { + public String getAuthorName() { // ----------------------------- return mystudy.getAuthor().toString(); } diff --git a/Workspace/Siman/src/org/splat/simer/StudyMenu.java b/Workspace/Siman/src/org/splat/simer/StudyMenu.java index e530e68..5577790 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyMenu.java +++ b/Workspace/Siman/src/org/splat/simer/StudyMenu.java @@ -12,197 +12,246 @@ import org.splat.dal.bo.som.Study; import org.splat.wapp.MenuItem; import org.splat.wapp.SlidMenu; - public class StudyMenu extends SlidMenu { - private Study study; - private Scenario scopen; // Currently "open" scenario - private Step stopen; // Currently selected step + private Study study; + private Scenario scopen; // Currently "open" scenario + private Step stopen; // Currently selected step private ScenarioService _scenarioService; private ProjectElementService _projectElementService; - -// ============================================================================================================================== -// Constructor -// ============================================================================================================================== - - public StudyMenu (Study context) { -// -------------------------------- - super("activities", "study"); - study = context; - scopen = null; - } - -// ============================================================================================================================== -// Member functions -// ============================================================================================================================== - - public void selects (String name) { -// --------------------------------- - String[] parse = name.split("\\x2E"); - Scenario[] scenes = study.getScenarii(); - Scenario scenew = scopen; - int askid = 0; - -// Initialization - if (scenew == null && scenes.length == 1) scenew = scenes[0]; - try { - int askdex = Integer.valueOf(parse[0]); - if (askdex > 0) { - while (askid < scenes.length) { - if (scenes[askid].getIndex() == askdex) break; - askid += 1; - } - scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct) - } - } catch (Exception error) { - return; - } - if (scenew == null) { - -// Study with several scenarii, non of them open -// Collection of steps to be displayed - Vector steps = new Vector(); - Step[] newstep = getProjectElementService().getSteps(scenes[0]); // All scenarii have the same steps - - int base = newstep[0].getNumber(); - int last = newstep[newstep.length-1].getNumber(); - for (int i=0; i-1; i--) { - if(newstep[i].getNumber() >= base) continue; - steps.add(0, newstep[i]); - } - for (int i=0; i i=steps.iterator(); i.hasNext(); ) { - Step step = i.next(); - int number = step.getNumber(); - String icon; - if (step.getOwner() instanceof Study) { - if (!step.isStarted()) icon = "icon.empty.png"; - else if (step.isFinished()) icon = "icon.checked.png"; - else icon = "icon.done.png"; - addItem("0." + number, "menu.step." + number, icon, "step-study?selection=0." + number); -// WARNING: The selection number must end the action's parameters for the need of refreshGivenStepItem() - } else { - Scenario group = (Scenario)step.getOwner(); - long index = group.getIndex(); - String value = index + "." + number; - if (group.isCheckedout()) icon = "icon.checkedout.png"; - else if (getScenarioService().isEmpty(group)) icon = "icon.empty.png"; -// else if (group.isFinished()) icon = "icon.checked.png"; - else icon = "icon.done.png"; - addGroup(value, group.getTitle(), icon, "step-study?selection=" + value); - } - } - } else - if (scopen == null || !scenew.equals(scopen)) { - -// Opening a scenario - this.clear(); -// Collection of steps to be displayed - Vector steps = new Vector(); - Step[] newstep = getProjectElementService().getSteps(scenew); - - int base = newstep[0].getNumber(); - int last = newstep[newstep.length-1].getNumber(); - for (int i=0; i-1; i--) steps.add(0, getProjectElementService().getFirstStep(scenes[i])); - newstep = getProjectElementService().getSteps(study); - for (int i=newstep.length-1; i>-1; i--) { - if(newstep[i].getNumber() >= base) continue; - steps.add(0, newstep[i]); - } - for (int i=askid+1; i i=steps.iterator(); i.hasNext(); ) { - Step step = i.next(); - int number = step.getNumber(); - String icon; - if (!step.isStarted()) icon = "icon.empty.png"; - else if (step.isFinished()) icon = "icon.checked.png"; - else icon = "icon.done.png"; - if (number == askdex) stopen = step; - if (step.getOwner() instanceof Study) { - addItem("0." + number, "menu.step." + number, icon, "step-study?selection=0." + number); - } else { - Scenario group = (Scenario)step.getOwner(); - long index = group.getIndex(); - String value = index + "." + number; - if (index != scenew.getIndex()) { - if (group.isCheckedout()) icon = "icon.checkedout.png"; - else if (getScenarioService().isEmpty(group)) icon = "icon.empty.png"; -// else if (group.isFinished()) icon = "icon.checked.png"; - else icon = "icon.done.png"; - addGroup(value, group.getTitle(), icon, "step-study?selection=" + value); - } else if (first) { - if (group.isCheckedout()) icon = "icon.checkedout.png"; - addGroup(value, scenew.getTitle(), icon, "step-study?selection=" + value); - first = false; - } else { - addSubItem(value, "menu.step." + number, icon, "step-study?selection=" + value); - } - } - } - scopen = scenew; - } - else { - Step[] step = getProjectElementService().getSteps(scopen); - int selected = Integer.valueOf(parse[1]); - for (int i=0; i action=menu.iterator(); action.hasNext(); ) { - MenuItem item = action.next(); - String index = item.getAction(); // Returns the above string ended by the selection number - if (!index.endsWith(number)) continue; - - String icon; - if (owner instanceof Scenario) { - if (range == 0 && ((Scenario)owner).isCheckedout()) icon = "icon.checkedout.png"; - range += 1; - } - if (!step.isStarted()) icon = "icon.empty.png"; - else if (step.isFinished()) icon = "icon.checked.png"; - else icon = "icon.done.png"; - item.icon(icon); - } - } - - public void refreshSelectedItem () { -// ---------------------------------- - MenuItem item = this.getSelectedItem(); - String icon; - if (!stopen.isStarted()) icon = "icon.empty.png"; - else if (stopen.isFinished()) icon = "icon.checked.png"; - else icon = "icon.done.png"; - item.icon(icon); - } + + // ============================================================================================================================== + // Constructor + // ============================================================================================================================== + + public StudyMenu() { + super("activities", "study"); + scopen = null; + } + + public StudyMenu init(Study context) { + study = context; + scopen = null; + return this; + } + + public StudyMenu(Study context) { + // -------------------------------- + super("activities", "study"); + study = context; + scopen = null; + } + + // ============================================================================================================================== + // Member functions + // ============================================================================================================================== + + public void selects(String name) { + // --------------------------------- + String[] parse = name.split("\\x2E"); + Scenario[] scenes = study.getScenarii(); + Scenario scenew = scopen; + int askid = 0; + + // Initialization + if (scenew == null && scenes.length == 1) + scenew = scenes[0]; + try { + int askdex = Integer.valueOf(parse[0]); + if (askdex > 0) { + while (askid < scenes.length) { + if (scenes[askid].getIndex() == askdex) + break; + askid += 1; + } + scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct) + } + } catch (Exception error) { + return; + } + if (scenew == null) { + + // Study with several scenarii, non of them open + // Collection of steps to be displayed + Vector steps = new Vector(); + Step[] newstep = getProjectElementService().getSteps(scenes[0]); // All scenarii have the same steps + + int base = newstep[0].getNumber(); + int last = newstep[newstep.length - 1].getNumber(); + for (int i = 0; i < scenes.length; i++) + steps.add(getProjectElementService().getFirstStep(scenes[i])); + + newstep = getProjectElementService().getSteps(study); + stopen = newstep[0]; // Default selected step + for (int i = newstep.length - 1; i > -1; i--) { + if (newstep[i].getNumber() >= base) + continue; + steps.add(0, newstep[i]); + } + for (int i = 0; i < newstep.length; i++) { + if (newstep[i].getNumber() <= last) + continue; + steps.add(newstep[i]); + } + // Creation of the menu + for (Iterator i = steps.iterator(); i.hasNext();) { + Step step = i.next(); + int number = step.getNumber(); + String icon; + if (step.getOwner() instanceof Study) { + if (!step.isStarted()) + icon = "icon.empty.png"; + else if (step.isFinished()) + icon = "icon.checked.png"; + else + icon = "icon.done.png"; + addItem("0." + number, "menu.step." + number, icon, + "step-study?selection=0." + number); + // WARNING: The selection number must end the action's parameters for the need of refreshGivenStepItem() + } else { + Scenario group = (Scenario) step.getOwner(); + long index = group.getIndex(); + String value = index + "." + number; + if (group.isCheckedout()) + icon = "icon.checkedout.png"; + else if (getScenarioService().isEmpty(group)) + icon = "icon.empty.png"; + // else if (group.isFinished()) icon = "icon.checked.png"; + else + icon = "icon.done.png"; + addGroup(value, group.getTitle(), icon, + "step-study?selection=" + value); + } + } + } else if (scopen == null || !scenew.equals(scopen)) { + + // Opening a scenario + this.clear(); + // Collection of steps to be displayed + Vector steps = new Vector(); + Step[] newstep = getProjectElementService().getSteps(scenew); + + int base = newstep[0].getNumber(); + int last = newstep[newstep.length - 1].getNumber(); + for (int i = 0; i < newstep.length; i++) { + steps.add(newstep[i]); + } + for (int i = askid - 1; i > -1; i--) + steps + .add(0, getProjectElementService().getFirstStep( + scenes[i])); + newstep = getProjectElementService().getSteps(study); + for (int i = newstep.length - 1; i > -1; i--) { + if (newstep[i].getNumber() >= base) + continue; + steps.add(0, newstep[i]); + } + for (int i = askid + 1; i < scenes.length; i++) + steps.add(getProjectElementService().getFirstStep(scenes[i])); + for (int i = 0; i < newstep.length; i++) { + if (newstep[i].getNumber() <= last) + continue; + steps.add(newstep[i]); + } + // Creation of the menu + boolean first = true; // For differentiating the first scenario step + int askdex = Integer.valueOf(parse[1]); + for (Iterator i = steps.iterator(); i.hasNext();) { + Step step = i.next(); + int number = step.getNumber(); + String icon; + if (!step.isStarted()) + icon = "icon.empty.png"; + else if (step.isFinished()) + icon = "icon.checked.png"; + else + icon = "icon.done.png"; + if (number == askdex) + stopen = step; + if (step.getOwner() instanceof Study) { + addItem("0." + number, "menu.step." + number, icon, + "step-study?selection=0." + number); + } else { + Scenario group = (Scenario) step.getOwner(); + long index = group.getIndex(); + String value = index + "." + number; + if (index != scenew.getIndex()) { + if (group.isCheckedout()) + icon = "icon.checkedout.png"; + else if (getScenarioService().isEmpty(group)) + icon = "icon.empty.png"; + // else if (group.isFinished()) icon = "icon.checked.png"; + else + icon = "icon.done.png"; + addGroup(value, group.getTitle(), icon, + "step-study?selection=" + value); + } else if (first) { + if (group.isCheckedout()) + icon = "icon.checkedout.png"; + addGroup(value, scenew.getTitle(), icon, + "step-study?selection=" + value); + first = false; + } else { + addSubItem(value, "menu.step." + number, icon, + "step-study?selection=" + value); + } + } + } + scopen = scenew; + } else { + Step[] step = getProjectElementService().getSteps(scopen); + int selected = Integer.valueOf(parse[1]); + for (int i = 0; i < step.length; i++) { + if (step[i].getNumber() != selected) + continue; + stopen = step[i]; + break; + } + } + super.selects(name); + } + + public void refreshGivenStepItem(Step step) { + // -------------------------------------------- + String number = "." + step.getNumber(); + ProjectElement owner = step.getOwner(); + int range = 0; + + for (Iterator action = menu.iterator(); action.hasNext();) { + MenuItem item = action.next(); + String index = item.getAction(); // Returns the above string ended by the selection number + if (!index.endsWith(number)) + continue; + + String icon; + if (owner instanceof Scenario) { + if (range == 0 && ((Scenario) owner).isCheckedout()) + icon = "icon.checkedout.png"; + range += 1; + } + if (!step.isStarted()) + icon = "icon.empty.png"; + else if (step.isFinished()) + icon = "icon.checked.png"; + else + icon = "icon.done.png"; + item.icon(icon); + } + } + + public void refreshSelectedItem() { + // ---------------------------------- + MenuItem item = this.getSelectedItem(); + String icon; + if (!stopen.isStarted()) + icon = "icon.empty.png"; + else if (stopen.isFinished()) + icon = "icon.checked.png"; + else + icon = "icon.done.png"; + item.icon(icon); + } + /** * Get the scenarioService. * diff --git a/Workspace/Siman/src/org/splat/wapp/Menu.java b/Workspace/Siman/src/org/splat/wapp/Menu.java index 7c36f35..fa43e40 100644 --- a/Workspace/Siman/src/org/splat/wapp/Menu.java +++ b/Workspace/Siman/src/org/splat/wapp/Menu.java @@ -1,4 +1,9 @@ package org.splat.wapp; + +import java.util.HashMap; +import java.util.List; +import java.util.Vector; + /** * Base abstract class defining the minimal services for implementing menus.
* A menu is an ordered list of named menu-items. Each menu-item is made of: @@ -21,12 +26,6 @@ package org.splat.wapp; * @see ContextualMenu * @author Daniel Brunier-Coulin */ - -import java.util.HashMap; -import java.util.List; -import java.util.Vector; - - public abstract class Menu { private String myname; diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 8348daa..bd1b83a 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -41,6 +41,18 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + + + + + + + + + - + + + + + + + + @@ -175,13 +197,6 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> ref="knowledgeElementService" /> - - - - - -- 2.39.2