1 package com.sri.emo.wizard.selection; 2 3 import com.jcorporate.expresso.core.db.DBException; 4 import com.sri.emo.dbobj.Node; 5 import com.sri.emo.wizard.PageMetadata; 6 import com.sri.emo.wizard.WizardException; 7 import com.sri.emo.wizard.defaults.EmoWizardPage; 8 9 import java.io.Serializable; 10 11 /*** 12 * Handles the execution of the decision matrix to find a wizard node and 13 * then provides a prompt to name the given wizard. 14 * 15 * @author Michael Rimov 16 * @version 1.0 17 */ 18 public class NameNodePage extends EmoWizardPage { 19 20 /*** 21 * 22 */ 23 private static final long serialVersionUID = 1L; 24 25 26 /*** 27 * Name the node page id. 28 */ 29 public static final String PAGE_ID = "-1"; 30 31 32 private String nodeId; 33 34 public NameNodePage(final Integer newId, final PageMetadata pageMetadata) { 35 super(newId, pageMetadata, null); 36 assert newId != null; 37 38 } 39 40 41 public Node getSelectedNode() throws WizardException { 42 try { 43 Node n = new Node(); 44 n.setNodeId(nodeId); 45 n.retrieve(); 46 return n; 47 } catch (DBException ex) { 48 throw new WizardException("Error querying node id defined in previous set.", ex); 49 } 50 } 51 52 53 public void setSelectedNodeId(String nodeId) { 54 this.nodeId = nodeId; 55 } 56 57 58 /*** 59 * Sets the data associated with the page. 60 * 61 * @param newData the new data for the page. 62 * @throws WizardException upon error. 63 */ 64 public void setData(final Serializable newData) throws WizardException { 65 if (newData == null) { 66 this.addError("You must enter a name for this page."); 67 } 68 69 String dataAsString = (String) newData; 70 if (dataAsString.length() == 0) { 71 this.addError("You must enter a name for this page."); 72 } 73 74 75 try { 76 Node n = new Node(); 77 n.setNodeTitle(dataAsString); 78 if (n.find()) { 79 this.addError("The name \"" + dataAsString + "\" already exists. Please choose another name"); 80 } 81 } catch (DBException ex) { 82 throw new WizardException("Error querying node to check title.", ex); 83 } 84 85 super.setData(newData); 86 } 87 88 }