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.components.SeparatorAction;
027: import com.metaboss.applications.designstudio.fieldstable.FieldsViewPanel;
028: import com.metaboss.applications.designstudio.propertiesdialogs.MessagePropertiesDialog;
029: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
030: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
031: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
032: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
033: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageClass;
037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageType;
038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
039:
040: /* BOMessage user object */
041:
042: public class MessageUserObject extends BaseUserObject {
043: public static final int ADD_FIELD = 1;
044:
045: private Message mMessage = null;
046: private AddNewFieldAction mAddNewFieldAction = new AddNewFieldAction();
047: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
048:
049: public MessageUserObject(Message pMessage) {
050: super (pMessage, Application.MESSAGE_ICON);
051: mMessage = pMessage;
052: }
053:
054: public MessageUserObject(Message pMessage, String pCaption,
055: int pMode) {
056: super (pMessage, pCaption, pMode);
057: mMessage = pMessage;
058: }
059:
060: // create new message
061: public static void addNewMessage(Servicemodule pServiceModule)
062: throws Exception {
063: new MessageUserObject(null).addNewObject(
064: getObjectPackage(pServiceModule), pServiceModule
065: .getMessages());
066: }
067:
068: // create new message
069: public static void addNewMessage(Namespace pNamespace)
070: throws Exception {
071: new MessageUserObject(null).addNewObject(
072: getObjectPackage(pNamespace), pNamespace.getMessages());
073: }
074:
075: // create new message
076: public static void addNewMessage(DataDictionary pDataDictionary)
077: throws Exception {
078: new MessageUserObject(null).addNewObject(
079: getObjectPackage(pDataDictionary), pDataDictionary
080: .getMessages());
081: }
082:
083: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
084: EnterpriseModelPackage lEnterpriseModelPackage = pPackage
085: .getEnterpriseModel();
086: MessageClass lClass = lEnterpriseModelPackage.getMessage();
087: return new MessageUserObject(lClass.createMessage());
088: }
089:
090: // return object root node captions
091: public String getRootNodeName() {
092: return Application.getString("messages_node");
093: }
094:
095: // convert tree element to an action code
096: public int convertCaptionToAction(String pCaption) {
097: if (pCaption.equals(Application.getString("fields_node")))
098: return ADD_FIELD;
099: else
100: return super .convertCaptionToAction(pCaption);
101: }
102:
103: public Message getMessage() {
104: return mMessage;
105: }
106:
107: // get object editor
108: public BasePropertiesDialog getObjectEditor() {
109: return new MessagePropertiesDialog();
110: }
111:
112: // add extra properties tabs
113: public void addExtraPropertiesTabs(JTabbedPane pTabbedPane) {
114: super .addExtraPropertiesTabs(pTabbedPane);
115: pTabbedPane.insertTab("Fields", null, new FieldsViewPanel(
116: mMessage), null, 1);
117: }
118:
119: // load object properties into grid control
120: public void loadObjectProperties(PropertiesTableModel pModel)
121: throws Exception {
122: super .loadObjectProperties(pModel);
123: if (pModel == null || mMessage == null)
124: return;
125:
126: MessageType lMessageType = mMessage.getType();
127: if (lMessageType != null)
128: pModel.AddProperty("Type", lMessageType.toString());
129: pModel.AddProperty("Default Text", mMessage.getDefaultText());
130: }
131:
132: // fill actions list
133: public void fillActionsList(ArrayList pList) {
134: switch (mMode) {
135: case ALL_ACTIONS:
136: super .fillActionsList(pList);
137: pList.add(new SeparatorAction());
138: pList.add(mAddNewFieldAction);
139: pList.add(new SeparatorAction());
140: pList.add(mShowDataTypeDependenciesAction);
141: break;
142: case ADD_FIELD:
143: pList.add(mAddNewFieldAction);
144: break;
145: }
146: }
147:
148: // add event
149: public void addField() throws Exception {
150: MessageFieldUserObject.addNewMessageField(mMessage);
151: }
152:
153: // can duplicate model element
154: public boolean canDuplicate() {
155: return true;
156: }
157:
158: // duplicate model element
159: public ModelElement duplicate() throws Exception {
160: Message lMessage = (Message) Application.sModelRepository
161: .duplicateModelElement(mMessage);
162: lMessage.setServicemodule(mMessage.getServicemodule());
163: lMessage.setNamespace(mMessage.getNamespace());
164: return lMessage;
165: }
166:
167: /* Actions */
168:
169: public class AddNewFieldAction extends BaseAction {
170: public AddNewFieldAction() {
171: super ("Add New Field", Application
172: .getAddIcon(Application.FIELDS_ICON));
173: }
174:
175: public void actionPerformed(ActionEvent e) {
176: try {
177: addField();
178: } catch (Throwable t) {
179: Application.processError(t);
180: }
181: }
182: }
183: }
|