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 javax.swing.JTabbedPane;
021:
022: import com.metaboss.applications.designstudio.Application;
023: import com.metaboss.applications.designstudio.BaseAction;
024: import com.metaboss.applications.designstudio.BasePropertiesDialog;
025: import com.metaboss.applications.designstudio.BaseUserObject;
026: import com.metaboss.applications.designstudio.attributestable.AttributesViewPanel;
027: import com.metaboss.applications.designstudio.components.SeparatorAction;
028: import com.metaboss.applications.designstudio.propertiesdialogs.ReportEntityPropertiesDialog;
029: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
030: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElement;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputEntity;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputEntityClass;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
036:
037: /* BOReportEntity user object class */
038:
039: public class ReportEntityUserObject extends BaseUserObject {
040: public static final int ADD_ATTRIBUTE = 1;
041:
042: private ReportOutputEntity mEntity = null;
043: private AddNewAttributeAction mAddNewAttributeAction = new AddNewAttributeAction();
044: private AddAllAttributesAction mAddAllAttributesAction = new AddAllAttributesAction();
045:
046: public ReportEntityUserObject(ReportOutputEntity pEntity) {
047: super (pEntity, Application.ENTITY_ICON);
048: mEntity = pEntity;
049: }
050:
051: public ReportEntityUserObject(ReportOutputEntity pEntity,
052: String pCaption, int pMode) {
053: super (pEntity, pCaption, pMode);
054: mEntity = pEntity;
055: }
056:
057: // create new Entity
058: public static ReportEntityUserObject addNewEntity(
059: ReportOutputElement pElement) throws Exception {
060: return (ReportEntityUserObject) new ReportEntityUserObject(null)
061: .addNewObject(getObjectPackage(pElement), pElement
062: .getOutputEntities());
063: }
064:
065: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
066: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
067: .getEnterpriseModel().getSystemImplementationModel();
068: ReportOutputEntityClass lClass = lSystemImplementationModelPackage
069: .getReportOutputEntity();
070: return new ReportEntityUserObject(lClass
071: .createReportOutputEntity());
072: }
073:
074: public ReportOutputEntity getEntity() {
075: return mEntity;
076: }
077:
078: // return object root node captions
079: public String getRootNodeName() {
080: return Application.getString("entities_node");
081: }
082:
083: // convert tree element to an action code
084: public int convertCaptionToAction(String pCaption) {
085: if (pCaption.equals(Application.getString("attributes_node")))
086: return ADD_ATTRIBUTE;
087: else
088: return super .convertCaptionToAction(pCaption);
089: }
090:
091: // fill actions list
092: public void fillActionsList(ArrayList pList) {
093: switch (mMode) {
094: case ALL_ACTIONS:
095: super .fillActionsList(pList);
096: pList.add(new SeparatorAction());
097: pList.add(mAddNewAttributeAction);
098: if (needToAddAttributes())
099: pList.add(mAddAllAttributesAction);
100: break;
101: case ADD_ATTRIBUTE:
102: pList.add(mAddNewAttributeAction);
103: if (needToAddAttributes())
104: pList.add(mAddAllAttributesAction);
105: break;
106: }
107: }
108:
109: // load object properties into grid control
110: public void loadObjectProperties(PropertiesTableModel pModel)
111: throws Exception {
112: super .loadObjectProperties(pModel);
113: if (pModel == null || mEntity == null)
114: return;
115:
116: addModelElement(pModel, "Entity", mEntity.getEntity());
117: pModel.AddProperty("Array", boolToString(mEntity.isArray()));
118: }
119:
120: public BasePropertiesDialog getObjectEditor() {
121: return new ReportEntityPropertiesDialog();
122: }
123:
124: // add extra properties tabs
125: public void addExtraPropertiesTabs(JTabbedPane pTabbedPane) {
126: pTabbedPane.insertTab("Attributes", null,
127: new AttributesViewPanel(mEntity), null, 1);
128: }
129:
130: // add new child attribute
131: public void addNewAttribute() throws Exception {
132: ReportEntityAttributeUserObject
133: .addNewReportEntityAttribute(mEntity);
134: }
135:
136: // add all attributes
137: public void addAllAttributes() throws Exception {
138: if (mEntity == null || mEntity.getEntity() == null)
139: return;
140:
141: Object[] lAttributes = mEntity.getEntity().getAttributes()
142: .toArray();
143: if (lAttributes != null && lAttributes.length > 0) {
144: for (int i = 0; i < lAttributes.length; i++) {
145: Attribute lAttribute = (Attribute) lAttributes[i];
146: if (!attributeAlreadyIn(lAttribute)) {
147: Application.beginTransaction();
148: try {
149: mEntity.getAttributes().add(lAttribute);
150: Application.commit();
151: } finally {
152: Application.checkAndRollback();
153: }
154: Application
155: .fireObjectInserted(new ReportEntityAttributeUserObject(
156: lAttribute, mEntity));
157: }
158: }
159: }
160: }
161:
162: // check attribute already added into attributes collection
163: private boolean attributeAlreadyIn(Attribute pAttribute) {
164: return mEntity.getAttributes().contains(pAttribute);
165: }
166:
167: // check as if there is a need to add attributes
168: private boolean needToAddAttributes() {
169: if (mEntity != null && mEntity.getEntity() != null) {
170: int lSize = mEntity.getEntity().getAttributes().size();
171: if (lSize > 0 && mEntity.getAttributes().size() < lSize)
172: return true;
173: }
174: return false;
175: }
176:
177: /* Auxilary classes */
178:
179: /* Add New Attribute Action Class */
180:
181: public class AddNewAttributeAction extends BaseAction {
182: public AddNewAttributeAction() {
183: super ("Add New Attribute", Application
184: .getAddIcon(Application.ATTRIBUTE_ICON));
185: }
186:
187: public void actionPerformed(ActionEvent arg0) {
188: try {
189: addNewAttribute();
190: } catch (Exception e) {
191: e.printStackTrace();
192: }
193: }
194: }
195:
196: /* Add all attributes */
197:
198: public class AddAllAttributesAction extends BaseAction {
199: public AddAllAttributesAction() {
200: super ("Add All Attributes",
201: Application.ADDALLATTRIBUTES_ICON);
202: }
203:
204: public void actionPerformed(ActionEvent arg0) {
205: try {
206: addAllAttributes();
207: } catch (Exception e) {
208: e.printStackTrace();
209: }
210: }
211: }
212: }
|