FieldsTableModel.java :  » UML » MetaBoss » com » metaboss » applications » designstudio » fieldstable » Java Open Source

Java Open Source » UML » MetaBoss 
MetaBoss » com » metaboss » applications » designstudio » fieldstable » FieldsTableModel.java
// THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
// OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright 2000-2005  Softaris Pty.Ltd. All Rights Reserved.
package com.metaboss.applications.designstudio.fieldstable;

import com.metaboss.applications.designstudio.BaseUserObject;
import com.metaboss.applications.designstudio.components.FieldsModel;
import com.metaboss.applications.designstudio.userobjects.AbstractDataFieldUserObject;
import com.metaboss.applications.designstudio.userobjects.EventDataFieldUserObject;
import com.metaboss.applications.designstudio.userobjects.EventMessageFieldUserObject;
import com.metaboss.applications.designstudio.userobjects.MessageFieldUserObject;
import com.metaboss.applications.designstudio.userobjects.OperationInputFieldUserObject;
import com.metaboss.applications.designstudio.userobjects.OperationOutputFieldUserObject;
import com.metaboss.applications.designstudio.userobjects.OperationOutputMessageUserObject;
import com.metaboss.applications.designstudio.userobjects.OperationUserObject;
import com.metaboss.applications.designstudio.userobjects.StructureFieldUserObject;
import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Event;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventDataField;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventMessageField;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicy;

/*     Fields table model      */

public class FieldsTableModel extends FieldsModel
{
  private int       mMode = 0;
  private ModelElement   mMaster = null;
  private Class      mElementClass = null;
  
  
  public FieldsTableModel(String pFirstColumn, String pSecondColumn)
  {
    super(pFirstColumn, pSecondColumn);
  }
  public FieldsTableModel()
  {
    super();
  }
  
  public void loadFields(ModelElement pElement) 
  {
    mMaster = pElement;
    mFields.clear();
    if (pElement!=null)
    {
      if (pElement instanceof Structure)
      {
        mElementClass = StructureField.class;
        Structure lStructure = (Structure)pElement; 
        Object[] lList = lStructure.getFields().toArray();
        for (int i=0; i<lList.length; i++)
          mFields.add(new StructureFieldUserObject((StructureField)lList[i]));
      }  else
      if (pElement instanceof Message)
      {
        mElementClass = MessageField.class;
        Message lMessage = (Message)pElement; 
        Object[] lList = lMessage.getFields().toArray();
        for (int i=0; i<lList.length; i++)
          mFields.add(new MessageFieldUserObject((MessageField)lList[i]));
      }  else
      if (pElement instanceof Service)
      {
        mElementClass = Operation.class;
        Service lService = (Service)pElement; 
        Object[] lList = lService.getOperations().toArray();
        for (int i=0; i<lList.length; i++)
          mFields.add(new OperationUserObject((Operation)lList[i]));
      }  else
      if (pElement instanceof Operation)
      {
        Operation   lOperation = (Operation)pElement;
        Object[]   lList = null; 
        switch (mMode)
        {
          case 1:
            mElementClass = OperationInputField.class;
            lList = lOperation.getInputFields().toArray();
            for (int i=0; i<lList.length; i++)
              mFields.add(new OperationInputFieldUserObject((OperationInputField)lList[i]));
            break;
          case 2:
            mElementClass = OperationOutputField.class;
            lList = lOperation.getOutputFields().toArray();
            for (int i=0; i<lList.length; i++)
              mFields.add(new OperationOutputFieldUserObject((OperationOutputField)lList[i]));
            break; 
          case 3:
            mElementClass = OperationOutputMessage.class;
            lList = lOperation.getOutputMessages().toArray();
            for (int i=0; i<lList.length; i++)
              mFields.add(new OperationOutputMessageUserObject((OperationOutputMessage)lList[i]));
            break;
        }
      }
            else if (pElement instanceof EventSubscriptionOperation)
            {
                EventSubscriptionOperation  lOperation = (EventSubscriptionOperation)pElement;
                Object[]                    lList = null; 
                switch (mMode)
                {
                    case 1:
                        mElementClass = OperationInputField.class;
                        lList = lOperation.getInputFields().toArray();
                        for (int i=0; i<lList.length; i++)
                            mFields.add(new OperationInputFieldUserObject((OperationInputField)lList[i]));
                        break;
                    case 2:
                        mElementClass = OperationOutputField.class;
                        lList = lOperation.getOutputFields().toArray();
                        for (int i=0; i<lList.length; i++)
                            mFields.add(new OperationOutputFieldUserObject((OperationOutputField)lList[i]));
                        break; 
                    case 3:
                        mElementClass = OperationOutputMessage.class;
                        lList = lOperation.getOutputMessages().toArray();
                        for (int i=0; i<lList.length; i++)
                            mFields.add(new OperationOutputMessageUserObject((OperationOutputMessage)lList[i]));
                        break;
                }
            }
            else if (pElement instanceof Event)
            {
                Event       lEvent = (Event)pElement;
                Object[]    lList = null; 
                switch (mMode)
                {
                    case 1:
                        mElementClass = EventDataField.class;
                        lList = lEvent.getDataFields().toArray();
                        for (int i=0; i<lList.length; i++)
                            mFields.add(new EventDataFieldUserObject((EventDataField)lList[i]));
                        break;
                    case 2:
                        mElementClass = EventMessageField.class;
                        lList = lEvent.getMessageFields().toArray();
                        for (int i=0; i<lList.length; i++)
                            mFields.add(new EventMessageFieldUserObject((EventMessageField)lList[i]));
                        break;
                }
            }
    }
    fireTableDataChanged();
  }  
  public void loadFields(ModelElement pElemnt, int pMode) 
  {
    mMode = pMode;
    loadFields(pElemnt);
  }
  
    public String getObjectType(BaseUserObject pObject)
    {
    DataType lDataType = null;
        if (pObject instanceof AbstractDataFieldUserObject)
        {
            lDataType = ((AbstractDataFieldUserObject)pObject).getAbstractField().getDataType();
            if (lDataType==null)
            {
                Structure lStructure = ((AbstractDataFieldUserObject)pObject).getAbstractField().getStructureType();
                if (lStructure!=null) return lStructure.getName();
            }
        }   else
    if (pObject instanceof StructureFieldUserObject)
        {
      lDataType = ((StructureFieldUserObject)pObject).getField().getDataType();
            if (lDataType==null)
            {
                Structure lStructure = ((StructureFieldUserObject)pObject).getField().getStructureType();
                if (lStructure!=null) return lStructure.getName();
            }
        }   else
    if (pObject instanceof MessageFieldUserObject)
      lDataType = ((MessageFieldUserObject)pObject).getField().getDataType();
      else
    if (pObject instanceof OperationInputFieldUserObject)
    {
      lDataType = ((OperationInputFieldUserObject)pObject).getField().getDataType();
      if (lDataType==null)
      {
        Structure lStructure = ((OperationInputFieldUserObject)pObject).getField().getStructureType();
        if (lStructure!=null) return lStructure.getName(); 
      }
      }  else
      if (pObject instanceof OperationUserObject)
      {
      TransactionPolicy lPolicy = ((OperationUserObject)pObject).getOperation().getTransactionPolicy();
      if (lPolicy!=null) return lPolicy.toString(); 
      }  else
    if (pObject instanceof OperationOutputFieldUserObject)
    {
      lDataType = ((OperationOutputFieldUserObject)pObject).getField().getDataType();
      if (lDataType==null)
      {
        Structure lStructure = ((OperationOutputFieldUserObject)pObject).getField().getStructureType();
        if (lStructure!=null) return lStructure.getName(); 
      }
    }  
        else if (pObject instanceof EventMessageFieldUserObject)
        {
            Message lMessage = ((EventMessageFieldUserObject)pObject).getField().getMessageType();
            if (lMessage!=null) return lMessage.getName(); 
        }
    else if (pObject instanceof OperationOutputMessageUserObject)
    {
      Message lMessage = ((OperationOutputMessageUserObject)pObject).getMessage().getMessageType();
      if (lMessage!=null) return lMessage.getName(); 
    }
        return (lDataType!=null) ? lDataType.getName() : super.getObjectType(pObject);
    }

  protected void processObjectInserted(BaseUserObject pObject)
  {
    if (mMaster!=null && pObject!=null && 
      mMaster.equals(pObject.getMasterElement()))
    {
      Class[] lInterfaces = pObject.getBOObject().getClass().getInterfaces();
      for (int i=0; i<lInterfaces.length; i++)
      {
        if (mElementClass!=null && mElementClass.equals(lInterfaces[i]))
        {
          mFields.add(pObject);
          fireTableDataChanged();
          break;
        }
      }      
    }
  }
    
    protected void processObjectEdited(BaseUserObject pObject)
    {
        if (mMaster!=null && pObject!=null && 
            mMaster.equals(pObject.getMasterElement()))
        {
            Class[] lInterfaces = pObject.getBOObject().getClass().getInterfaces();
            for (int i=0; i<lInterfaces.length; i++)
            {
                if (mElementClass!=null && mElementClass.equals(lInterfaces[i]))
                {
                    fireTableDataChanged();
                    break;
                }
            }           
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.