001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.userobjects;
016:
017: import java.awt.event.ActionEvent;
018: import java.util.ArrayList;
019:
020: import com.metaboss.applications.designstudio.Application;
021: import com.metaboss.applications.designstudio.BaseAction;
022: import com.metaboss.applications.designstudio.BasePropertiesDialog;
023: import com.metaboss.applications.designstudio.BaseUserObject;
024: import com.metaboss.applications.designstudio.components.SeparatorAction;
025: import com.metaboss.applications.designstudio.propertiesdialogs.SimpleObjectPropertiesdialog;
026: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
027: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Report;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElement;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElementClass;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
032:
033: /* ReportOutputElement user object */
034:
035: public class OutputElementUserObject extends BaseUserObject {
036: public static final int ADD_OUTPUTFIELD = 1;
037: public static final int ADD_ENTITY = 2;
038:
039: private Report mReport = null;
040: private ReportOutputElement mOutputElement = null;
041: private ReportOutputElement mElement = null;
042: private AddNewOutputFieldAction mAddNewOutputFieldAction = new AddNewOutputFieldAction();
043: private AddTopLevelOutputElementAction mAddTopLevelOutputElementAction = new AddTopLevelOutputElementAction();
044: private AddNewEntityAction mAddNewEntityAction = new AddNewEntityAction();
045:
046: public OutputElementUserObject(ReportOutputElement pElement) {
047: super (pElement, Application.REPORTOUTPUTELEMENT_ICON);
048: mElement = pElement;
049: }
050:
051: public OutputElementUserObject(ReportOutputElement pElement,
052: String pCaption, int pMode) {
053: super (pElement, pCaption, pMode);
054: mElement = pElement;
055: }
056:
057: public static OutputElementUserObject addNewOutputElement(
058: Report pReport) throws Exception {
059: return (OutputElementUserObject) new OutputElementUserObject(
060: null).addNewObject(getObjectPackage(pReport), pReport);
061: }
062:
063: public static OutputElementUserObject addNewOutputElement(
064: ReportOutputElement pElement) throws Exception {
065: return (OutputElementUserObject) new OutputElementUserObject(
066: null)
067: .addNewObject(getObjectPackage(pElement), pElement);
068: }
069:
070: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
071: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
072: .getEnterpriseModel().getSystemImplementationModel();
073: ReportOutputElementClass lClass = lSystemImplementationModelPackage
074: .getReportOutputElement();
075: ReportOutputElement lElement = lClass
076: .createReportOutputElement();
077: if (mReport != null)
078: mReport.setTopLevelOutputElement(lElement);
079: if (mOutputElement != null)
080: mOutputElement.setSubElement(lElement);
081: mReport = null;
082: mOutputElement = null;
083: return new OutputElementUserObject(lElement);
084: }
085:
086: // add new object
087: public BaseUserObject addNewObject(MetaBossModelPackage pPackage,
088: Report pReport) throws Exception {
089: mReport = pReport;
090: return super .addNewObject(pPackage, null);
091: }
092:
093: public BaseUserObject addNewObject(MetaBossModelPackage pPackage,
094: ReportOutputElement pElement) throws Exception {
095: mOutputElement = pElement;
096: return super .addNewObject(pPackage, null);
097: }
098:
099: public ReportOutputElement getReportOutputElement() {
100: return mElement;
101: }
102:
103: // return object root node captions
104: public String getRootNodeName() {
105: return null;
106: }
107:
108: // load object properties into grid control
109: public void loadObjectProperties(PropertiesTableModel pModel)
110: throws Exception {
111: super .loadObjectProperties(pModel);
112: if (pModel == null || mElement == null)
113: return;
114:
115: pModel.AddProperty("Level", new Integer(mElement
116: .getLevelIndex()).toString());
117: }
118:
119: // fill actions list
120: public void fillActionsList(ArrayList pList) {
121: switch (mMode) {
122: case ALL_ACTIONS:
123: //super.fillActionsList(pList);
124: pList.add(getEditAction());
125: pList.add(getDeleteAction());
126: pList.add(new SeparatorAction());
127: pList.add(mAddNewOutputFieldAction);
128: if (mElement != null && mElement.getSubElement() == null)
129: pList.add(mAddTopLevelOutputElementAction);
130: pList.add(mAddNewEntityAction);
131: break;
132: case ADD_OUTPUTFIELD:
133: pList.add(mAddNewOutputFieldAction);
134: break;
135: case ADD_ENTITY:
136: pList.add(mAddNewEntityAction);
137: break;
138: }
139: }
140:
141: public BasePropertiesDialog getObjectEditor() {
142: return new SimpleObjectPropertiesdialog("Report Output Element");
143: }
144:
145: private void addOutputField() throws Exception {
146: ReportOutputFieldUserObject.addNewReportOutputField(mElement);
147: }
148:
149: private void addTopLevelOutputElement() throws Exception {
150: OutputElementUserObject.addNewOutputElement(mElement);
151: }
152:
153: private void addEntityField() throws Exception {
154: ReportEntityUserObject.addNewEntity(mElement);
155: }
156:
157: /* Actions */
158:
159: public class AddNewOutputFieldAction extends BaseAction {
160: public AddNewOutputFieldAction() {
161: super ("Add New Output Field", Application
162: .getAddIcon(Application.FIELDS_ICON));
163: }
164:
165: public void actionPerformed(ActionEvent e) {
166: try {
167: addOutputField();
168: } catch (Throwable t) {
169: Application.processError(t);
170: }
171: }
172: }
173:
174: public class AddTopLevelOutputElementAction extends BaseAction {
175: public AddTopLevelOutputElementAction() {
176: super ("Add Top Level Output Element", Application
177: .getAddIcon(Application.REPORTOUTPUTELEMENT_ICON));
178: }
179:
180: public void actionPerformed(ActionEvent e) {
181: try {
182: addTopLevelOutputElement();
183: } catch (Throwable t) {
184: Application.processError(t);
185: }
186: }
187: }
188:
189: public class AddNewEntityAction extends BaseAction {
190: public AddNewEntityAction() {
191: super ("Add New Report Output Entity", Application
192: .getAddIcon(Application.ENTITY_ICON));
193: }
194:
195: public void actionPerformed(ActionEvent e) {
196: try {
197: addEntityField();
198: } catch (Throwable t) {
199: Application.processError(t);
200: }
201: }
202: }
203: }
|