/*
* ChainBuilder ESB
* Visual Enterprise Integration
*
* Copyright (C) 2006 Bostech Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* $Id$
*/
package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.rules;
import org.eclipse.gmf.runtime.notation.View;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BaseElement;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BindingComponent;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBR;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DecorativeModelElement;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DefaultMepType;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FTP;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.File;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JMS;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.MessageExchange;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RegularType;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Script;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Sequencer;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.MessageExchangeEditPart;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.BindingComponentImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.CBRImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.FTPImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.FileImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.HTTPImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.JMSImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.ScriptImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.SequencerImpl;
import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.impl.TCPIPImpl;
public class RuleStrategy {
public MessageExchangeEditPart editPart;
public RuleFactory ruleFactory = null;
MessageExchange object;
BaseElement target_component;
BaseElement source_component;
public RuleStrategy(MessageExchangeEditPart editPart)
{
this.editPart = editPart;
object = (MessageExchange) ((View) editPart.getModel())
.getElement();
target_component = object.getTargetElement();
source_component = object.getSourceElement();
ruleFactory = new RuleFactory(this.editPart, source_component, target_component);
}
public DefaultMepType getDefault_MEP()
{
if(ruleFactory != null)
return ruleFactory.getDefault_MEP();
else
{
return DefaultMepType.INOUT_LITERAL;
}
}
public void modifyExpression()
{
if(source_component instanceof CBR)
{
if(object.getType().equals(RegularType.EXACT_LITERAL))
object.setLabel(object.getExpression());
}
}
public void refreshTargetDel(MessageExchangeEditPart editPart)
{
if(ruleFactory != null)
ruleFactory.refreshTargetDel(editPart);
}
public void refreshSourceDel()
{
if(ruleFactory != null)
ruleFactory.refreshSourceDel();
}
public RuleFactory getRuleFactory()
{
return ruleFactory;
}
public void refreshTarget()
{
if(ruleFactory != null)
ruleFactory.refreshTarget();
}
public void refreshSource()
{
if(ruleFactory != null)
ruleFactory.refreshSource();
}
public boolean sourceTargetIsConnection()
{
/*object = (MessageExchange) ((View) editPart.getModel()).getElement();
target_component = object.getTargetElement();
source_component = object.getSourceElement();
ruleFactory = new RuleFactory(this.editPart, source_component,
target_component);*/
return ruleFactory.isConnected();
}
public void addAdapters()
{
editPart.getDiagramEdge().getElement().eAdapters().add(editPart.getDomainModelRefresher());
// fetch the default mep for each type of the component, put them in the
// adapter
if(source_component instanceof BindingComponent)
{
if(!(target_component instanceof DecorativeModelElement))
((BindingComponentImpl) source_component).getConsumer().eAdapters().add(editPart.getDomainModelRefresher());
else
((BindingComponentImpl) source_component).getProvider().eAdapters().add(editPart.getDomainModelRefresher());
}
else if(source_component instanceof DecorativeModelElement)
{
if(target_component instanceof BindingComponent)
{
((BindingComponentImpl) target_component).getConsumer().eAdapters().add(editPart.getDomainModelRefresher());
}
}
}
public void removeAdapters()
{
editPart.getDiagramEdge().getElement().eAdapters().remove(editPart.getDomainModelRefresher());
// first get the connection itself
// fetch the default mep for each type of the component, put them in the
// adapter
if(source_component instanceof BindingComponent)
{
if(!(target_component instanceof DecorativeModelElement))
((BindingComponentImpl) source_component).getConsumer().eAdapters().remove(editPart.getDomainModelRefresher());
else
((BindingComponentImpl) source_component).getProvider().eAdapters().remove(editPart.getDomainModelRefresher());
}
else if(source_component instanceof DecorativeModelElement)
{
if(target_component instanceof BindingComponent)
{
((BindingComponentImpl) target_component).getConsumer().eAdapters().remove(editPart.getDomainModelRefresher());
}
}
}
}
|