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.ServicePropertiesDialog;
029: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.ServiceClass;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
035:
036: /* BOService user object class */
037:
038: public class ServiceUserObject extends BaseUserObject {
039: public static final int ADD_IMPLEMENTATION = 1;
040: public static final int ADD_OPERATION = 2;
041:
042: private Service mService = null;
043: private AddNewImplementationAction mAddNewImplementationAction = new AddNewImplementationAction();
044: private AddNewOperationAction mAddNewOperationAction = new AddNewOperationAction();
045: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
046:
047: public ServiceUserObject(Service pService) {
048: super (pService, Application.SERVICEMODULESERVICE_ICON);
049: mService = pService;
050: }
051:
052: public ServiceUserObject(Service pService, String pCaption,
053: int pMode) {
054: super (pService, pCaption, pMode);
055: mService = pService;
056: }
057:
058: // create new service
059: public static void addNewService(Servicemodule pServiceModule)
060: throws Exception {
061: new ServiceUserObject(null).addNewObject(
062: getObjectPackage(pServiceModule), pServiceModule
063: .getServices());
064: }
065:
066: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
067: EnterpriseModelPackage lEnterpriseModelPackage = pPackage
068: .getEnterpriseModel();
069: ServiceClass lClass = lEnterpriseModelPackage.getService();
070: return new ServiceUserObject(lClass.createService());
071: }
072:
073: // return object root node captions
074: public String getRootNodeName() {
075: return Application.getString("services_node");
076: }
077:
078: // convert tree element to an action code
079: public int convertCaptionToAction(String pCaption) {
080: if (pCaption.equals(Application
081: .getString("implementations_node")))
082: return ADD_IMPLEMENTATION;
083: else if (pCaption.equals(Application
084: .getString("operations_node")))
085: return ADD_OPERATION;
086: else
087: return super .convertCaptionToAction(pCaption);
088: }
089:
090: public Service getService() {
091: return mService;
092: }
093:
094: // get object editor
095: public BasePropertiesDialog getObjectEditor() {
096: return new ServicePropertiesDialog();
097: }
098:
099: // fill actions list
100: public void fillActionsList(ArrayList pList) {
101: switch (mMode) {
102: case ALL_ACTIONS:
103: super .fillActionsList(pList);
104: pList.add(new SeparatorAction());
105: pList.add(mAddNewImplementationAction);
106: pList.add(mAddNewOperationAction);
107: pList.add(new SeparatorAction());
108: pList.add(mShowDataTypeDependenciesAction);
109: break;
110: case ADD_IMPLEMENTATION:
111: pList.add(mAddNewImplementationAction);
112: break;
113: case ADD_OPERATION:
114: pList.add(mAddNewOperationAction);
115: break;
116: }
117: }
118:
119: // add new BOServiceImplementation object
120: private void addServiceImplementation() throws Exception {
121: ServiceImplementationUserObject
122: .addNewServiceImplementation(mService);
123: }
124:
125: // add new BOOperation object
126: private void addOperation() throws Exception {
127: OperationUserObject.addNewOperation(mService);
128: }
129:
130: // add extra properties tabs
131: public void addExtraPropertiesTabs(JTabbedPane pTabbedPane) {
132: pTabbedPane.insertTab("Operations", null, new FieldsViewPanel(
133: mService, 4), null, 1);
134: }
135:
136: // returns true if drop object could be accepted
137: public boolean canAcceptDropObject(BaseUserObject pUserObject,
138: boolean pCopy) {
139: if (pUserObject != null) {
140: if ((pUserObject instanceof OperationUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == ServiceUserObject.ADD_OPERATION))) {
141: return (pCopy) ? pUserObject.canDuplicate() : true;
142: }
143: }
144: return false;
145: }
146:
147: // acccept drop target in transaction
148: protected void transactionalAccept(BaseUserObject pUserObject,
149: boolean pCopy) throws Exception {
150: if (pUserObject != null) {
151: if (pUserObject instanceof OperationUserObject) {
152: OperationUserObject lUserObject = (OperationUserObject) pUserObject;
153: if (pCopy) {
154: Operation lOperation = (Operation) Application.sModelRepository
155: .duplicateModelElement(lUserObject
156: .getOperation());
157: lOperation.setService(mService);
158: } else
159: lUserObject.getOperation().setService(mService);
160: }
161: }
162: }
163:
164: /* Actions */
165:
166: public class AddNewImplementationAction extends BaseAction {
167: public AddNewImplementationAction() {
168: super ("Add New Implementation", Application
169: .getAddIcon(Application.SERVICEIMPL_ICON));
170: }
171:
172: public void actionPerformed(ActionEvent e) {
173: try {
174: addServiceImplementation();
175: } catch (Throwable t) {
176: Application.processError(t);
177: }
178: }
179: }
180:
181: public class AddNewOperationAction extends BaseAction {
182: public AddNewOperationAction() {
183: super ("Add New Operation", Application
184: .getAddIcon(Application.OPERATION_ICON));
185: }
186:
187: public void actionPerformed(ActionEvent e) {
188: try {
189: addOperation();
190: } catch (Throwable t) {
191: t.printStackTrace();
192: }
193: }
194: }
195: }
|