001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.rules;
025:
026: import java.util.List;
027:
028: import org.eclipse.gmf.runtime.notation.View;
029: import org.eclipse.swt.SWT;
030: import org.eclipse.swt.widgets.MessageBox;
031:
032: import com.bostechcorp.cbesb.common.i18n.I18N;
033: import com.bostechcorp.cbesb.common.i18n.Messages;
034: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BaseElement;
035: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BindingComponent;
036: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBR;
037: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DefaultMepType;
038: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FTP;
039: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.File;
040: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
041: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JMS;
042: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.MessageExchange;
043: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Parser;
044: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RegularType;
045: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Script;
046: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Sequencer;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Transformer;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.XSLT;
050: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.CBREditPart;
051: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.MessageExchangeEditPart;
052:
053: public class CbrSource extends Source {
054:
055: public CBR cbr;
056: //public BaseElement target;
057: MessageExchangeEditPart editPart;
058:
059: public CbrSource(MessageExchangeEditPart editPart, CBR cbr,
060: BaseElement target) {
061: super (cbr, target);
062: this .editPart = editPart;
063: }
064:
065: public boolean asSource() {
066: if (RulesUtil.lineLoop(editPart, target)) {
067: editPart.setLoop(true);
068: return false;
069:
070: }
071:
072: else
073: editPart.setLoop(false);
074:
075: if (RulesUtil.targetMultiLineOut(cbr)) {
076: if (getDefaultMepTypeForNewConn().equals(
077: DefaultMepType.INOUT_LITERAL)) {
078: String text = I18N.getString(Messages.COMP_SUG);
079: String message = I18N
080: .getString(Messages.COMP_CBR_SOURCE);
081: MessageBox messageBox = RuleFactory.getMessageBox(text,
082: message);
083: int buttonID = messageBox.open();
084:
085: return false;
086: }
087:
088: }
089: return true;
090: }
091:
092: public void refreshCbrSourceConnection() {
093:
094: CBREditPart source_editpart = (CBREditPart) editPart
095: .getSource();
096: List list = null;
097: try {
098: list = source_editpart.getSourceConnections();
099: } catch (Exception e) {
100: // TODO: Eric Lu are you ignore exception?
101: return;
102: }
103:
104: for (int i = 0; i < list.size(); i++) {
105: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
106: .get(i);
107: if (!this .editPart.equals(connectionEditPart)) {
108: connectionEditPart
109: .changeConnection(getDefaultMepTypeForNewConn());
110:
111: }
112:
113: View model = (View) connectionEditPart.getModel();
114: MessageExchange object_connection = (MessageExchange) model
115: .getElement();
116: // object_connection.setExpression("1");
117: if (object_connection.getType().equals(
118: RegularType.EXACT_LITERAL))
119: object_connection.setLabel(object_connection
120: .getExpression());
121:
122: }
123:
124: }
125:
126: // this method is going to refresh the connections coming out of the CBR source.
127:
128: public DefaultMepType getDefaultMepTypeForDelConn(
129: MessageExchangeEditPart editpart) {
130:
131: CBREditPart source_editpart = (CBREditPart) editPart
132: .getSource();
133: // put all the connection into this sequencer in a list
134: DefaultMepType default_mep = null;
135: if (source_editpart != null) {
136: List list = null;
137: list = source_editpart.getTargetConnections();
138: if ((list == null) || list.size() == 0)
139: return DefaultMepType.INONLY_LITERAL;
140:
141: for (int i = 0; i < list.size(); i++) {
142: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
143: .get(i);
144:
145: if (connectionEditPart.equals(editpart))
146: continue;
147: View model = (View) connectionEditPart.getModel();
148: MessageExchange object = (MessageExchange) model
149: .getElement();
150: BaseElement source_element = object.getSourceElement();
151:
152: if (source_element instanceof Sequencer) {
153: default_mep = ((SequencerSource) connectionEditPart
154: .getRuleStrategy().getRuleFactory()
155: .getSource())
156: .getDefaultMepTypeForDelConn(editpart);
157: } else if (source_element instanceof CBR) {
158: default_mep = ((CbrSource) connectionEditPart
159: .getRuleStrategy().getRuleFactory()
160: .getSource())
161: .getDefaultMepTypeForDelConn(editpart);
162: } else if (source_element instanceof TCPIP) {
163: default_mep = ((TCPIP) source_element)
164: .getConsumer().getDefaultMep();
165: } else {
166: default_mep = ((BindingComponent) source_element)
167: .getConsumer().getDefaultMep();
168: }
169:
170: if (default_mep.equals(DefaultMepType.INOUT_LITERAL))
171: break;
172: }
173: }
174: if (!(default_mep == null)) {
175: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
176: default_mep = DefaultMepType.INONLY_LITERAL;
177: }
178: } else {
179: default_mep = DefaultMepType.INONLY_LITERAL;
180: }
181: return default_mep;
182: // return DefaultMepType.INONLY_LITERAL;
183: }
184:
185: public DefaultMepType getDefaultMepTypeForNewConn() {
186:
187: CBREditPart source_editpart = (CBREditPart) editPart
188: .getSource();
189: // put all the connection into this sequencer in a list
190: DefaultMepType default_mep = null;
191:
192: if (source_editpart != null) {
193: List list = null;
194: list = source_editpart.getTargetConnections();
195: if ((list == null) || list.size() == 0)
196: return DefaultMepType.INONLY_LITERAL;
197:
198: for (int i = 0; i < list.size(); i++) {
199: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
200: .get(i);
201:
202: View model = (View) connectionEditPart.getModel();
203: MessageExchange object = (MessageExchange) model
204: .getElement();
205: BaseElement source_element = object.getSourceElement();
206:
207: if (source_element instanceof Sequencer) {
208: default_mep = ((SequencerSource) connectionEditPart
209: .getRuleStrategy().getRuleFactory()
210: .getSource()).getDefaultMepTypeForNewConn();
211: } else if (source_element instanceof CBR) {
212: default_mep = ((CbrSource) connectionEditPart
213: .getRuleStrategy().getRuleFactory()
214: .getSource()).getDefaultMepTypeForNewConn();
215: } else {
216: default_mep = ((BindingComponent) source_element)
217: .getConsumer().getDefaultMep();
218: }
219:
220: if (default_mep.equals(DefaultMepType.INOUT_LITERAL))
221: break;
222: }
223: }
224: if (!(default_mep == null)) {
225: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
226: default_mep = DefaultMepType.INONLY_LITERAL;
227: }
228: } else {
229: default_mep = DefaultMepType.INONLY_LITERAL;
230: }
231:
232: return default_mep;
233: }
234: }
|