001: package com.salmonllc.examples.example7;
002:
003: //The Salmon Open Framework for Internet Applications (SOFIA)
004: //Copyright (C) 1999 - 2002, Salmon LLC
005: //
006: //This program is free software; you can redistribute it and/or
007: //modify it under the terms of the GNU General Public License version 2
008: //as published by the Free Software Foundation;
009: //
010: //This program is distributed in the hope that it will be useful,
011: //but WITHOUT ANY WARRANTY; without even the implied warranty of
012: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: //GNU General Public License for more details.
014: //
015: //You should have received a copy of the GNU General Public License
016: //along with this program; if not, write to the Free Software
017: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: //
019: //For more information please visit http://www.salmonllc.com
020:
021: import com.salmonllc.properties.Props;
022: import com.salmonllc.sql.*;
023: import com.salmonllc.jsp.JspNavBar;
024:
025: import java.sql.SQLException;
026:
027: /**
028: * Most of this model was generated by the IDE Tool Utility. One method was hand code: populateNavBar which takes the tata from the model and fills in a navbar gui component.
029: */
030: public class ExamplesModel extends DataStore {
031:
032: //constants for columns
033: public static final String EXAMPLES_NAME = "examples.name";
034: public static final String EXAMPLES_PAGE_URL = "examples.page_url";
035: public static final String SOURCE_CODE_FILENAME = "source_code.filename";
036: public static final String SOURCE_CODE_EXAMPLE_ID = "source_code.example_id";
037:
038: public ExamplesModel(String appName) {
039: super (appName);
040:
041: //add columns
042: addColumn(computeTableName("examples"), "name",
043: DataStore.DATATYPE_STRING, false, true, EXAMPLES_NAME);
044: addColumn(computeTableName("examples"), "page_url",
045: DataStore.DATATYPE_STRING, false, true,
046: EXAMPLES_PAGE_URL);
047: addColumn(computeTableName("source_code"), "filename",
048: DataStore.DATATYPE_STRING, true, true,
049: SOURCE_CODE_FILENAME);
050: addColumn(computeTableName("source_code"), "example_id",
051: DataStore.DATATYPE_INT, true, true,
052: SOURCE_CODE_EXAMPLE_ID);
053:
054: //add joins
055: addJoin(computeTableAndFieldName("examples.example_id"),
056: computeTableAndFieldName("source_code.example_id"),
057: false);
058:
059: //set order by
060: setOrderBy(computeTableAndFieldName("source_code.example_id")
061: + " ASC");
062: }
063:
064: /**
065: * Populates a navigation component with the contents of the model
066: */
067: public void populateNavBar(JspNavBar nav, int groupNo)
068: throws SQLException, DataStoreException {
069: retrieve();
070: //Each row has one sub menu item with a source code file.
071: //The examples are repeated if an example only has more that one source file associated with it.
072: //So each row should have a sub item, but only add an item if the example changes.
073: int lastExampleID = -1;
074: for (int i = 0; i < getRowCount(); i++) {
075: if (lastExampleID != getSourceCodeExampleId(i)) {
076: //add a group item if the example id changes
077: lastExampleID = getSourceCodeExampleId(i);
078: String name = "example" + lastExampleID; //unique name for the group
079: String url = getExamplesPageUrl(i); //url to go to when user click the group
080: String subName = "subMenu" + lastExampleID; //unique name of submenu for this group
081: nav.addGroupItem(name, groupNo, getExamplesName(i),
082: url, null, 0, subName);
083: }
084: //add a sub item for each row
085: addSubItem(nav, lastExampleID, i);
086: }
087: }
088:
089: /**
090: * Adds a sub item to a navigation bar group
091: */
092: private void addSubItem(JspNavBar nav, int lastExampleID, int row)
093: throws DataStoreException {
094: //compute the name of this sub item, each sub item must have a unique name
095: String name = "sub" + row;
096:
097: //compute the description for the sub item
098: String description = getSourceCodeFilename(row);
099: int pos = description.lastIndexOf("/");
100: if (pos > -1)
101: description = description.substring(pos + 1);
102:
103: //compute the url that will be invoked when the the user clicks on the item
104: String url = "%SourceView?file=" + getSourceCodeFilename(row);
105:
106: //compute the parent menu name. This is the name of the item that this group will fall under.
107: String parentMenuName = "example" + lastExampleID;
108:
109: //Color for sub items
110: String bgColor = nav.getPage().getPageProperties().getProperty(
111: Props.NAVBAR_SHOW_POPUP_BG_COLOR);
112:
113: //add the item to the group
114: nav.addSubItem(name, description, url, null, 0, parentMenuName,
115: null, bgColor);
116: }
117:
118: public String getExamplesName() throws DataStoreException {
119: return getString(EXAMPLES_NAME);
120: }
121:
122: public String getExamplesName(int row) throws DataStoreException {
123: return getString(row, EXAMPLES_NAME);
124: }
125:
126: public void setExamplesName(String newValue)
127: throws DataStoreException {
128: setString(EXAMPLES_NAME, newValue);
129: }
130:
131: public void setExamplesName(int row, String newValue)
132: throws DataStoreException {
133: setString(row, EXAMPLES_NAME, newValue);
134: }
135:
136: public String getExamplesPageUrl() throws DataStoreException {
137: return getString(EXAMPLES_PAGE_URL);
138: }
139:
140: public String getExamplesPageUrl(int row) throws DataStoreException {
141: return getString(row, EXAMPLES_PAGE_URL);
142: }
143:
144: public void setExamplesPageUrl(String newValue)
145: throws DataStoreException {
146: setString(EXAMPLES_PAGE_URL, newValue);
147: }
148:
149: public void setExamplesPageUrl(int row, String newValue)
150: throws DataStoreException {
151: setString(row, EXAMPLES_PAGE_URL, newValue);
152: }
153:
154: public String getSourceCodeFilename() throws DataStoreException {
155: return getString(SOURCE_CODE_FILENAME);
156: }
157:
158: public String getSourceCodeFilename(int row)
159: throws DataStoreException {
160: return getString(row, SOURCE_CODE_FILENAME);
161: }
162:
163: public void setSourceCodeFilename(String newValue)
164: throws DataStoreException {
165: setString(SOURCE_CODE_FILENAME, newValue);
166: }
167:
168: public void setSourceCodeFilename(int row, String newValue)
169: throws DataStoreException {
170: setString(row, SOURCE_CODE_FILENAME, newValue);
171: }
172:
173: public int getSourceCodeExampleId() throws DataStoreException {
174: return getInt(SOURCE_CODE_EXAMPLE_ID);
175: }
176:
177: public int getSourceCodeExampleId(int row)
178: throws DataStoreException {
179: return getInt(row, SOURCE_CODE_EXAMPLE_ID);
180: }
181:
182: public void setSourceCodeExampleId(int newValue)
183: throws DataStoreException {
184: setInt(SOURCE_CODE_EXAMPLE_ID, newValue);
185: }
186:
187: public void setSourceCodeExampleId(int row, int newValue)
188: throws DataStoreException {
189: setInt(row, SOURCE_CODE_EXAMPLE_ID, newValue);
190: }
191: }
|