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:
030: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BaseElement;
031: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BindingComponent;
032: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBR;
033: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DefaultMepType;
034: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.MessageExchange;
035: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Sequencer;
036: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
037: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.MessageExchangeEditPart;
038: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.SequencerEditPart;
039:
040: public class SequencerSource extends Source {
041:
042: public Sequencer sequencer;
043: public BaseElement target;
044: MessageExchangeEditPart editPart;
045:
046: public SequencerSource(MessageExchangeEditPart editPart,
047: Sequencer sequencer, BaseElement target) {
048: super (sequencer, target);
049: this .sequencer = sequencer;
050: this .target = target;
051: this .editPart = editPart;
052: }
053:
054: public void setEditpart(MessageExchangeEditPart editPart) {
055: this .editPart = editPart;
056: }
057:
058: public boolean asSource() {
059:
060: // return false;
061:
062: SequencerEditPart source = (SequencerEditPart) editPart
063: .getSource();
064: if (source != null) {
065:
066: List list_connection = source.getSourceConnections();
067: View model = (View) editPart.getModel();
068: MessageExchange object_connection = (MessageExchange) model
069: .getElement();
070: if (object_connection.getLabel().equals("")) {
071: object_connection.setLabel("0");
072: int num = RuleFactory.maximum(list_connection) + 1;
073:
074: object_connection.setLabel("" + num);
075: }
076: }
077:
078: if (RulesUtil.lineLoop(editPart, target)) {
079: editPart.setLoop(true);
080: return false;
081:
082: }
083:
084: else
085: editPart.setLoop(false);
086: return true;
087: }
088:
089: // this method is going to refresh the connections coming out of the sequencer source.
090: public void refreshSequncerSourceConnectionPostCr() {
091:
092: SequencerEditPart source_editpart = (SequencerEditPart) editPart
093: .getSource();
094: List list = null;
095: // put all connecions out of this sequencer source into a list
096:
097: if (source_editpart != null) {
098: try {
099: list = source_editpart.getSourceConnections();
100: } catch (Exception e) {
101: // TODO ignore?
102: return;
103: }
104: int num = RuleFactory.maximum(list);
105:
106: for (int i = 0; i < list.size(); i++) {
107: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
108: .get(i);
109: View model = (View) connectionEditPart.getModel();
110: MessageExchange object_connection = (MessageExchange) model
111: .getElement();
112:
113: int mynum = 0;
114: try {
115: mynum = Integer.parseInt(object_connection
116: .getLabel());
117: } catch (Exception e) {
118: // TODO ignore?
119: continue;
120: }
121:
122: // 0 means that this comnnection is the first one coming out of this source.
123: if (num == 0)
124: // 0 means that this comnnection is the first one coming out of this source.
125: connectionEditPart
126: .changeConnection(getDefaultMepTypeForNewConn());
127: else {
128: if (mynum == num)
129: connectionEditPart
130: .changeConnection(getDefaultMepTypeForNewConn());
131:
132: else {
133: // If connection doesn't have the largest order, the default mep will be INOUT.
134: connectionEditPart
135: .changeConnection(DefaultMepType.INOUT_LITERAL);
136: }
137: }
138:
139: }
140: }
141: }
142:
143: public void refreshSequncerSourceConnection() {
144:
145: SequencerEditPart source_editpart = (SequencerEditPart) editPart
146: .getSource();
147: List list = null;
148: try {
149: list = source_editpart.getSourceConnections();
150: } catch (Exception e) {
151: // TODO ignore
152: return;
153: }
154:
155: for (int i = 0; i < list.size(); i++) {
156: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
157: .get(i);
158:
159: if (!this .editPart.equals(connectionEditPart)) {
160: connectionEditPart
161: .changeConnection(DefaultMepType.INOUT_LITERAL);
162:
163: } else {
164:
165: }
166:
167: }
168: }
169:
170: public DefaultMepType getDefaultMepTypeForNewConn() {
171:
172: SequencerEditPart source_editpart = (SequencerEditPart) editPart
173: .getSource();
174: // put all the connection into this sequencer in a list
175:
176: DefaultMepType default_mep = null;
177:
178: if (source_editpart != null) {
179: List list = null;
180: list = source_editpart.getTargetConnections();
181: if ((list == null) || list.size() == 0)
182: return DefaultMepType.INONLY_LITERAL;
183:
184: for (int i = 0; i < list.size(); i++) {
185: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
186: .get(i);
187:
188: View model = (View) connectionEditPart.getModel();
189: MessageExchange object = (MessageExchange) model
190: .getElement();
191: BaseElement source_element = object.getSourceElement();
192:
193: if (source_element instanceof Sequencer) {
194: default_mep = ((SequencerSource) connectionEditPart
195: .getRuleStrategy().getRuleFactory()
196: .getSource()).getDefaultMepTypeForNewConn();
197: } else if (source_element instanceof CBR) {
198: default_mep = ((CbrSource) connectionEditPart
199: .getRuleStrategy().getRuleFactory()
200: .getSource()).getDefaultMepTypeForNewConn();
201: } else if (source_element instanceof TCPIP) {
202: default_mep = ((TCPIP) source_element)
203: .getConsumer().getDefaultMep();
204: } else {
205: default_mep = ((BindingComponent) source_element)
206: .getConsumer().getDefaultMep();
207: }
208:
209: if (default_mep.equals(DefaultMepType.INOUT_LITERAL))
210: break;
211: }
212: }
213:
214: if (!(default_mep == null)) {
215: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
216: default_mep = DefaultMepType.INONLY_LITERAL;
217: }
218: } else {
219: default_mep = DefaultMepType.INONLY_LITERAL;
220: }
221:
222: return default_mep;
223:
224: }
225:
226: public void refreshSequncerSourceConnectionDel() {
227:
228: SequencerEditPart source_editpart = (SequencerEditPart) editPart
229: .getSource();
230: List list = null;
231: try {
232: list = source_editpart.getSourceConnections();
233: } catch (Exception e) {
234: // TODO ignore?
235: return;
236: }
237: int num = RuleFactory.postdel_maximum(list, this .editPart);
238:
239: for (int i = 0; i < list.size(); i++) {
240: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
241: .get(i);
242:
243: if (!this .editPart.equals(connectionEditPart)) {
244: View model = (View) connectionEditPart.getModel();
245: MessageExchange object_connection = (MessageExchange) model
246: .getElement();
247:
248: int mynum = Integer.parseInt(object_connection
249: .getLabel());
250:
251: if (mynum < num)
252: connectionEditPart
253: .changeConnection(DefaultMepType.INOUT_LITERAL);
254: else if (mynum == num)
255: connectionEditPart
256: .changeConnection(getDefaultMepTypeForNewConn());
257:
258: }
259:
260: }
261:
262: }
263:
264: public DefaultMepType getDefaultMepTypeForDelConn(
265: MessageExchangeEditPart editpart) {
266:
267: SequencerEditPart source_editpart = (SequencerEditPart) editPart
268: .getSource();
269: // put all the connection into this sequencer in a list
270: DefaultMepType default_mep = null;
271: if (source_editpart != null) {
272: List list = null;
273: list = source_editpart.getTargetConnections();
274: if ((list == null) || list.size() == 0)
275: return DefaultMepType.INONLY_LITERAL;
276:
277: for (int i = 0; i < list.size(); i++) {
278: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
279: .get(i);
280:
281: if (connectionEditPart.equals(editpart))
282: continue;
283: View model = (View) connectionEditPart.getModel();
284: MessageExchange object = (MessageExchange) model
285: .getElement();
286: BaseElement source_element = object.getSourceElement();
287:
288: if (source_element instanceof Sequencer) {
289: default_mep = ((SequencerSource) connectionEditPart
290: .getRuleStrategy().getRuleFactory()
291: .getSource())
292: .getDefaultMepTypeForDelConn(editpart);
293: } else if (source_element instanceof CBR) {
294: default_mep = ((CbrSource) connectionEditPart
295: .getRuleStrategy().getRuleFactory()
296: .getSource())
297: .getDefaultMepTypeForDelConn(editpart);
298: } else {
299: default_mep = ((BindingComponent) source_element)
300: .getConsumer().getDefaultMep();
301: }
302:
303: if (default_mep.equals(DefaultMepType.INOUT_LITERAL))
304: break;
305: }
306: }
307: if (!(default_mep == null)) {
308: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
309: default_mep = DefaultMepType.INONLY_LITERAL;
310: }
311: } else {
312: default_mep = DefaultMepType.INONLY_LITERAL;
313: }
314: return default_mep;
315:
316: }
317:
318: }
|