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 SequencerTarget extends Target {
041:
042: public Sequencer sequencer;
043: // public BaseElement source;
044:
045: public MessageExchangeEditPart editPart;
046:
047: public SequencerTarget(MessageExchangeEditPart editPart,
048: BaseElement source, Sequencer sequencer) {
049: super (source, sequencer);
050: this .sequencer = sequencer;
051: this .source = source;
052: this .editPart = editPart;
053: }
054:
055: public boolean asTarget() {
056:
057: /*if(RulesUtil.lineLoop(editPart, sequencer))
058: {
059: editPart.setLoop(true);
060: return true;
061:
062: }*/
063:
064: return true;
065: }
066:
067: // this method will refresh the connections out of the sequencer target
068: public void refreshSequncerSourceConnection() {
069:
070: SequencerEditPart target_editpart = (SequencerEditPart) editPart
071: .getTarget();
072: List list = null;
073: if (target_editpart != null) {
074: try {
075: list = target_editpart.getSourceConnections();
076: } catch (Exception e) {
077: // TODO ignore?
078: return;
079: }
080: int num = RuleFactory.maximum(list);
081:
082: for (int i = 0; i < list.size(); i++) {
083: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
084: .get(i);
085: if (!connectionEditPart.getLoop()) {
086: if (num == 0) {
087:
088: connectionEditPart
089: .changeConnection(getDefaultMepTypeForNewConn());
090: } else {
091: View model = (View) connectionEditPart
092: .getModel();
093: MessageExchange object_connection = (MessageExchange) model
094: .getElement();
095: int mynum = 0;
096: try {
097: mynum = Integer.parseInt(object_connection
098: .getLabel());
099: } catch (Exception ex) {
100: ex.printStackTrace();
101: }
102: if (mynum < num)
103: connectionEditPart
104: .changeConnection(DefaultMepType.INOUT_LITERAL);
105: else
106: connectionEditPart
107: .changeConnection(getDefaultMepTypeForNewConn());
108: }
109: // we need to refresh the target connections until the end
110: connectionEditPart.getRuleStrategy()
111: .refreshTarget();
112: }
113:
114: }
115: }
116:
117: }
118:
119: // this method will refresh the connections before the deleting.
120: public void refreshSequncerSourceConnectionDel(
121: MessageExchangeEditPart editpart) {
122: SequencerEditPart target_editpart = (SequencerEditPart) editPart
123: .getTarget();
124: List list = null;
125: List list_source = null;
126: if (target_editpart != null) {
127: try {
128: list = target_editpart.getSourceConnections();
129: list_source = target_editpart.getTargetConnections();
130: } catch (Exception e) {
131: e.printStackTrace();
132: }
133:
134: int num = RuleFactory.maximum(list);
135: // System.out.println("max is "+num);
136: // System.out.println("list_source size is "+list_source.size());
137:
138: for (int i = 0; i < list.size(); i++) {
139: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
140: .get(i);
141: if (!connectionEditPart.getLoop()) {
142: if (num == 0) {
143:
144: connectionEditPart
145: .changeConnection(getDefaultMepTypeForDelConn(editpart));
146: } else {
147: View model = (View) connectionEditPart
148: .getModel();
149: MessageExchange object_connection = (MessageExchange) model
150: .getElement();
151: int mynum = Integer.parseInt(object_connection
152: .getLabel());
153: if (mynum < num)
154: connectionEditPart
155: .changeConnection(DefaultMepType.INOUT_LITERAL);
156: else
157: connectionEditPart
158: .changeConnection(getDefaultMepTypeForDelConn(editpart));
159: }
160:
161: connectionEditPart.getRuleStrategy()
162: .refreshTargetDel(editpart);
163: }
164:
165: }
166: }
167:
168: }
169:
170: public DefaultMepType getDefaultMepTypeForDelConn(
171: MessageExchangeEditPart editpart) {
172: SequencerEditPart source_editpart = (SequencerEditPart) editPart
173: .getTarget();
174: // put all the connection into this sequencer in a list
175: DefaultMepType default_mep = null;
176: if (source_editpart != null) {
177: List list = null;
178: list = source_editpart.getTargetConnections();
179: if ((list == null) || list.size() == 0)
180: return DefaultMepType.INONLY_LITERAL;
181: // System.out.println("the size into sequencer is not 0 but "+ list.size());
182:
183: for (int i = 0; i < list.size(); i++) {
184: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
185: .get(i);
186:
187: if (connectionEditPart.equals(editpart))
188: continue;
189: View model = (View) connectionEditPart.getModel();
190: MessageExchange object = (MessageExchange) model
191: .getElement();
192: BaseElement source_element = object.getSourceElement();
193:
194: if (source_element instanceof Sequencer) {
195: default_mep = ((SequencerSource) connectionEditPart
196: .getRuleStrategy().getRuleFactory()
197: .getSource())
198: .getDefaultMepTypeForDelConn(editpart);
199: } else if (source_element instanceof CBR) {
200: default_mep = ((CbrSource) connectionEditPart
201: .getRuleStrategy().getRuleFactory()
202: .getSource())
203: .getDefaultMepTypeForDelConn(editpart);
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: if (!(default_mep == null)) {
214: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
215: default_mep = DefaultMepType.INONLY_LITERAL;
216: }
217: } else {
218: default_mep = DefaultMepType.INONLY_LITERAL;
219: }
220:
221: return default_mep;
222: }
223:
224: public DefaultMepType getDefaultMepTypeForNewConn() {
225:
226: SequencerEditPart source_editpart = (SequencerEditPart) editPart
227: .getTarget();
228: // put all the connection into this sequencer in a list
229: DefaultMepType default_mep = null;
230: if (source_editpart != null) {
231: List list = null;
232: list = source_editpart.getTargetConnections();
233: if ((list == null) || list.size() == 0)
234: return DefaultMepType.INONLY_LITERAL;
235:
236: for (int i = 0; i < list.size(); i++) {
237: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
238: .get(i);
239:
240: View model = (View) connectionEditPart.getModel();
241: MessageExchange object = (MessageExchange) model
242: .getElement();
243: BaseElement source_element = object.getSourceElement();
244:
245: if (source_element instanceof Sequencer) {
246: default_mep = ((SequencerSource) connectionEditPart
247: .getRuleStrategy().getRuleFactory()
248: .getSource()).getDefaultMepTypeForNewConn();
249: } else if (source_element instanceof CBR) {
250: default_mep = ((CbrSource) connectionEditPart
251: .getRuleStrategy().getRuleFactory()
252: .getSource()).getDefaultMepTypeForNewConn();
253: } else {
254: default_mep = ((BindingComponent) source_element)
255: .getConsumer().getDefaultMep();
256: }
257:
258: if (default_mep.equals(DefaultMepType.INOUT_LITERAL))
259: break;
260: }
261: }
262:
263: if (!(default_mep == null)) {
264: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
265: default_mep = DefaultMepType.INONLY_LITERAL;
266: }
267: } else {
268: default_mep = DefaultMepType.INONLY_LITERAL;
269: }
270: return default_mep;
271: }
272: }
|