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.MessageExchange;
039: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Sequencer;
040: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
041: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.CBREditPart;
042: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.MessageExchangeEditPart;
043:
044: public class CbrTarget extends Target {
045: public CBR cbr;
046: // public BaseElement source;
047: MessageExchangeEditPart editPart;
048:
049: public CbrTarget(MessageExchangeEditPart editPart,
050: BaseElement source, CBR cbr) {
051: super (cbr, source);
052: this .editPart = editPart;
053: }
054:
055: public boolean asTarget() {
056:
057: /*cbr.get*/
058: if (RulesUtil.targetMultiLineOut(cbr)) {
059:
060: if (getDefaultMepTypeForLastConnIn().equals(
061: DefaultMepType.INOUT_LITERAL)) {
062: String text = I18N.getString(Messages.COMP_SUG);
063: String message = I18N
064: .getString(Messages.COMP_CBR_SOURCE);
065: MessageBox messageBox = RuleFactory.getMessageBox(text,
066: message);
067: int buttonID = messageBox.open();
068:
069: return false;
070: }
071: } else
072: editPart.setLoop(false);
073: return true;
074: }
075:
076: public void refreshCbrSourceConnectionDel(
077: MessageExchangeEditPart editpart) {
078:
079: CBREditPart target_editpart = (CBREditPart) editPart
080: .getTarget();
081: List list = null;
082: if (target_editpart != null) {
083:
084: try {
085: list = target_editpart.getSourceConnections();
086: } catch (Exception e) {
087: e.printStackTrace();
088: }
089:
090: for (int i = 0; i < list.size(); i++) {
091: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
092: .get(i);
093: if (!connectionEditPart.getLoop()) {
094: connectionEditPart
095: .changeConnection(getDefaultMepTypeForDelConn(editpart));
096: connectionEditPart.getRuleStrategy()
097: .refreshTargetDel(editpart);
098: }
099: }
100: }
101:
102: }
103:
104: public void refreshCbrSourceConnection() {
105:
106: CBREditPart target_editpart = (CBREditPart) editPart
107: .getTarget();
108: List list = null;
109: if (target_editpart != null) {
110: try {
111: list = target_editpart.getSourceConnections();
112: } catch (Exception e) {
113: // TODO ignore?
114: return;
115: }
116:
117: for (int i = 0; i < list.size(); i++) {
118: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
119: .get(i);
120: if (!connectionEditPart.getLoop()) {
121: connectionEditPart
122: .changeConnection(getDefaultMepTypeForNewConn());
123: // we need to refresh the target connections until the end
124: connectionEditPart.getRuleStrategy()
125: .refreshTarget();
126: }
127: }
128: }
129:
130: }
131:
132: public DefaultMepType getDefaultMepTypeForLastConnIn() {
133: DefaultMepType default_mep = null;
134: BaseElement source_element = this .source;
135:
136: if (source_element instanceof Sequencer) {
137: default_mep = ((SequencerSource) this .editPart
138: .getRuleStrategy().getRuleFactory().getSource())
139: .getDefaultMepTypeForNewConn();
140: } else if (source_element instanceof CBR) {
141: default_mep = ((CbrSource) this .editPart.getRuleStrategy()
142: .getRuleFactory().getSource())
143: .getDefaultMepTypeForNewConn();
144: } else {
145: default_mep = ((BindingComponent) source_element)
146: .getConsumer().getDefaultMep();
147: }
148:
149: if (!(default_mep == null)) {
150: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
151: default_mep = DefaultMepType.INONLY_LITERAL;
152: }
153: } else {
154: default_mep = DefaultMepType.INONLY_LITERAL;
155: }
156: return default_mep;
157: }
158:
159: public DefaultMepType getDefaultMepTypeForNewConn() {
160:
161: CBREditPart source_editpart = (CBREditPart) editPart
162: .getTarget();
163: // put all the connection into this sequencer in a list
164: DefaultMepType default_mep = null;
165: if (source_editpart != null) {
166: List list = null;
167: list = source_editpart.getTargetConnections();
168: if ((list == null) || list.size() == 0)
169: return DefaultMepType.INONLY_LITERAL;
170:
171: for (int i = 0; i < list.size(); i++) {
172: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
173: .get(i);
174:
175: View model = (View) connectionEditPart.getModel();
176: MessageExchange object = (MessageExchange) model
177: .getElement();
178: BaseElement source_element = object.getSourceElement();
179:
180: if (source_element instanceof Sequencer) {
181: default_mep = ((SequencerSource) connectionEditPart
182: .getRuleStrategy().getRuleFactory()
183: .getSource()).getDefaultMepTypeForNewConn();
184: } else if (source_element instanceof CBR) {
185: default_mep = ((CbrSource) connectionEditPart
186: .getRuleStrategy().getRuleFactory()
187: .getSource()).getDefaultMepTypeForNewConn();
188: } else {
189: default_mep = ((BindingComponent) source_element)
190: .getConsumer().getDefaultMep();
191: }
192:
193: if (default_mep.equals(DefaultMepType.INOUT_LITERAL))
194: break;
195: }
196: }
197: if (!(default_mep == null)) {
198: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
199: default_mep = DefaultMepType.INONLY_LITERAL;
200: }
201: } else {
202: default_mep = DefaultMepType.INONLY_LITERAL;
203: }
204: return default_mep;
205:
206: }
207:
208: public DefaultMepType getDefaultMepTypeForDelConn(
209: MessageExchangeEditPart editpart) {
210:
211: CBREditPart source_editpart = (CBREditPart) editPart
212: .getTarget();
213: // put all the connection into this sequencer in a list
214: DefaultMepType default_mep = null;
215: if (source_editpart != null) {
216: List list = null;
217: list = source_editpart.getTargetConnections();
218: if ((list == null) || list.size() == 0)
219: return DefaultMepType.INONLY_LITERAL;
220:
221: for (int i = 0; i < list.size(); i++) {
222: MessageExchangeEditPart connectionEditPart = (MessageExchangeEditPart) list
223: .get(i);
224:
225: if (connectionEditPart.equals(editpart))
226: continue;
227: View model = (View) connectionEditPart.getModel();
228: MessageExchange object = (MessageExchange) model
229: .getElement();
230: BaseElement source_element = object.getSourceElement();
231:
232: if (source_element instanceof Sequencer) {
233: default_mep = ((SequencerSource) connectionEditPart
234: .getRuleStrategy().getRuleFactory()
235: .getSource())
236: .getDefaultMepTypeForDelConn(editpart);
237: } else if (source_element instanceof CBR) {
238: default_mep = ((CbrSource) connectionEditPart
239: .getRuleStrategy().getRuleFactory()
240: .getSource())
241: .getDefaultMepTypeForDelConn(editpart);
242: } else {
243: default_mep = ((BindingComponent) source_element)
244: .getConsumer().getDefaultMep();
245: }
246:
247: if (default_mep.equals(DefaultMepType.INOUT_LITERAL))
248: break;
249: }
250: }
251: if (!(default_mep == null)) {
252: if (!default_mep.equals(DefaultMepType.INOUT_LITERAL)) {
253: default_mep = DefaultMepType.INONLY_LITERAL;
254: }
255: } else {
256: default_mep = DefaultMepType.INONLY_LITERAL;
257: }
258: return default_mep;
259:
260: // return DefaultMepType.INONLY_LITERAL;
261: }
262: }
|