0001: package org.enhydra.jawe.components.graph;
0002:
0003: import java.awt.Color;
0004: import java.awt.Component;
0005: import java.awt.Cursor;
0006: import java.awt.Graphics;
0007: import java.awt.Point;
0008: import java.awt.Rectangle;
0009: import java.awt.event.MouseEvent;
0010: import java.awt.geom.Rectangle2D;
0011: import java.util.ArrayList;
0012: import java.util.HashSet;
0013: import java.util.List;
0014: import java.util.Set;
0015: import java.util.Vector;
0016:
0017: import javax.swing.JMenuItem;
0018: import javax.swing.JOptionPane;
0019: import javax.swing.JPopupMenu;
0020: import javax.swing.SwingUtilities;
0021:
0022: import org.enhydra.jawe.BarFactory;
0023: import org.enhydra.jawe.JaWEConstants;
0024: import org.enhydra.jawe.JaWEManager;
0025: import org.enhydra.jawe.Utils;
0026: import org.enhydra.jawe.base.controller.JaWEController;
0027: import org.enhydra.jawe.base.controller.JaWEFrame;
0028: import org.enhydra.shark.xpdl.XMLElement;
0029: import org.enhydra.shark.xpdl.XMLUtil;
0030: import org.enhydra.shark.xpdl.XPDLConstants;
0031: import org.enhydra.shark.xpdl.elements.Activities;
0032: import org.enhydra.shark.xpdl.elements.Activity;
0033: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
0034: import org.enhydra.shark.xpdl.elements.Participant;
0035: import org.enhydra.shark.xpdl.elements.Participants;
0036: import org.enhydra.shark.xpdl.elements.Transition;
0037: import org.enhydra.shark.xpdl.elements.Transitions;
0038: import org.jgraph.JGraph;
0039: import org.jgraph.graph.AbstractCellView;
0040: import org.jgraph.graph.BasicMarqueeHandler;
0041: import org.jgraph.graph.CellView;
0042: import org.jgraph.graph.DefaultGraphCell;
0043: import org.jgraph.graph.GraphConstants;
0044:
0045: /**
0046: * Implementation of a marquee handler for Process Editor. This is also a place
0047: * where (after mouse click or release) participants, activities (normal, subflows,
0048: * block activities) and transitions are inserted, where persistent mode is achived and
0049: * where mouse cursors are changing, and where popup menu is implemented. When
0050: * inserting cells it calls WorkflowManager.
0051: */
0052: public class GraphMarqueeHandler extends BasicMarqueeHandler {
0053: protected Point start; // Starting point (where mouse was pressed).
0054: protected Point current; // Current point (where mouse was dragged).
0055:
0056: protected GraphPortViewInterface port; // Current port (when mouse was pressed).
0057: protected GraphPortViewInterface firstPort; // First port (when mouse was pressed).
0058: protected GraphPortViewInterface lastPort; // Last port (when mouse was dragged).
0059:
0060: protected Vector points = new Vector();
0061:
0062: protected Point popupPoint; // A point where popup window has been created last time
0063:
0064: protected GraphController graphController;
0065:
0066: protected String mainType = GraphEAConstants.SELECT_TYPE;
0067: protected String subType = GraphEAConstants.SELECT_TYPE_DEFAULT;
0068:
0069: /**
0070: * Creates custom marquee handler.
0071: */
0072: public GraphMarqueeHandler(GraphController graphController) {
0073: this .graphController = graphController;
0074:
0075: // if (!JaWEConfig.getInstance().getUseBubblesStatus()) {
0076: // enableBubblesButtons(false);
0077: // }
0078: }
0079:
0080: /** Return true if this handler should be preferred over other handlers. */
0081: public boolean isForceMarqueeEvent(MouseEvent e) {
0082: boolean isSelectButtonSelected = isSelectButtonSelected();
0083: return ((isSelectButtonSelected && SwingUtilities
0084: .isRightMouseButton(e))
0085: || !isSelectButtonSelected || super
0086: .isForceMarqueeEvent(e));
0087: }
0088:
0089: /**
0090: * We don't want special cursor
0091: */
0092: public void mousePressed(MouseEvent e) {
0093: startPoint = e.getPoint();
0094: marqueeBounds = new Rectangle2D.Double(startPoint.getX(),
0095: startPoint.getY(), 0, 0);
0096: if (e != null) {
0097: if (!(e.getSource() instanceof JGraph))
0098: throw new IllegalArgumentException(
0099: "MarqueeHandler cannot handle event from unknown source: "
0100: + e);
0101: }
0102: }
0103:
0104: public void mouseReleased(MouseEvent ev) {
0105: try {
0106: if (ev != null && marqueeBounds != null) {
0107: Rectangle2D bounds = getGraph().fromScreen(
0108: marqueeBounds);// HM, JGraph3.4.1
0109: CellView[] rootViews = getGraph().getGraphLayoutCache()
0110: .getRoots(bounds);
0111:
0112: // added - getting all views in model (except forbidden objects)
0113: CellView[] views = AbstractCellView
0114: .getDescendantViews(rootViews);
0115: ArrayList wholeList = new ArrayList();
0116: ArrayList participantList = new ArrayList();
0117: ArrayList otherList = new ArrayList();
0118: for (int i = 0; i < views.length; i++) {
0119: if (bounds.contains(views[i].getBounds())) {
0120: if (views[i].getCell() instanceof DefaultGraphCell
0121: && !(((DefaultGraphCell) views[i]
0122: .getCell()).getUserObject() instanceof Participant)) {
0123: otherList.add(views[i].getCell());
0124: } else {
0125: participantList.add(views[i].getCell());
0126: }
0127: wholeList.add(views[i].getCell());
0128: }
0129: }
0130:
0131: Object[] cells = wholeList.toArray();
0132:
0133: getGraph().getUI().selectCellsForEvent(getGraph(),
0134: cells, ev);
0135: Rectangle dirty = marqueeBounds.getBounds();// HM, JGraph3.4.1
0136: dirty.width++;
0137: dirty.height++;// HM, JGraph3.4.1
0138: getGraph().repaint(dirty);
0139: }
0140: } finally {
0141: currentPoint = null;
0142: startPoint = null;
0143: marqueeBounds = null;
0144: }
0145: }
0146:
0147: //
0148: // PopupMenu
0149: //
0150: /**
0151: * Creates popup menu and adds a various actions (depending of where
0152: * mouse was pressed - which cell(s) is/are selected).
0153: */
0154: protected JPopupMenu createPopupMenu(final Object cell) {
0155:
0156: boolean isWorkflowElement = (cell instanceof WorkflowElement);
0157:
0158: String type = null;
0159: String subtype = null;
0160: String userSpec = null;
0161: if (isWorkflowElement) {
0162: XMLElement el = (XMLElement) ((DefaultGraphCell) cell)
0163: .getUserObject();
0164: if (cell instanceof GraphActivityInterface
0165: && !(cell instanceof GraphBubbleActivityInterface)) {
0166: type = JaWEConstants.ACTIVITY_TYPE;
0167: subtype = Utils.getActivityStringType(((Activity) el)
0168: .getActivityType());
0169: userSpec = JaWEManager.getInstance()
0170: .getJaWEController().getTypeResolver()
0171: .getJaWEType(el).getTypeId();
0172: }
0173: if (cell instanceof GraphParticipantInterface) {
0174: type = JaWEConstants.PARTICIPANT_TYPE;
0175: subtype = JaWEManager.getInstance().getJaWEController()
0176: .getTypeResolver().getJaWEType(el).getTypeId();
0177: }
0178: if (cell instanceof GraphTransitionInterface) {
0179: type = JaWEConstants.TRANSITION_TYPE;
0180: subtype = JaWEManager.getInstance().getJaWEController()
0181: .getTypeResolver().getJaWEType(el).getTypeId();
0182: }
0183: if (cell instanceof GraphBubbleActivityInterface) {
0184: if (((GraphBubbleActivityInterface) cell).isStart()) {
0185: type = GraphEAConstants.START_TYPE;
0186: } else {
0187: type = GraphEAConstants.END_TYPE;
0188: }
0189: subtype = ((GraphBubbleActivityInterface) cell)
0190: .getType();
0191: }
0192: } else {
0193: type = GraphEAConstants.SELECT_TYPE;
0194: }
0195:
0196: JPopupMenu retMenu = BarFactory.createPopupMenu(type,
0197: graphController);
0198:
0199: if (subtype != null) {
0200: JPopupMenu specMenu = BarFactory.createPopupMenu(subtype,
0201: graphController);
0202:
0203: Component[] spec = specMenu.getComponents();
0204:
0205: if (spec.length != 0)
0206: retMenu.addSeparator();
0207:
0208: for (int i = 0; i < spec.length; i++) {
0209: retMenu.add(spec[i]);
0210: }
0211: }
0212:
0213: if (subtype != null && userSpec != null
0214: && !subtype.equals(userSpec)) {
0215: JPopupMenu specMenu = BarFactory.createPopupMenu(userSpec,
0216: graphController);
0217:
0218: Component[] spec = specMenu.getComponents();
0219:
0220: if (spec.length != 0)
0221: retMenu.addSeparator();
0222:
0223: for (int i = 0; i < spec.length; i++) {
0224: retMenu.add(spec[i]);
0225: }
0226: }
0227:
0228: if (cell instanceof GraphParticipantInterface
0229: && ((WorkflowElement) cell).getPropertyObject() instanceof CommonExpressionParticipant) {
0230: // System.err.println("CSPEC FIR CEP");
0231: JMenuItem se = BarFactory.createMenuItem(
0232: getGraphController().getSettings().getAction(
0233: ("SetPerformerExpression")),
0234: getGraphController(), false);
0235: retMenu.addSeparator();
0236: retMenu.add(se);
0237: // System.err.println("CSPEC FIR CEP CREATED");
0238: }
0239:
0240: return retMenu;
0241: }
0242:
0243: /**
0244: * Gets the point of last popup menu creation.
0245: */
0246: public Point getPopupPoint() {
0247: return popupPoint;
0248: }
0249:
0250: public boolean validateSource(GraphPortViewInterface pPort) {
0251: // if port is a valid
0252: if (pPort != null && pPort.getCell() != null
0253: // and it is a port
0254: && (pPort.getCell() instanceof GraphPortInterface)) {
0255: // return if it accepts to be a source or a target
0256: GraphActivityInterface sourceActivity = pPort
0257: .getGraphActivity();
0258: if (!sourceActivity.acceptsSource())
0259: return false;
0260:
0261: boolean isExceptionalTrans = getSubType().equals(
0262: JaWEConstants.TRANSITION_TYPE_EXCEPTION);
0263: if (!(sourceActivity instanceof GraphBubbleActivityInterface)
0264: && !JaWEManager.getInstance()
0265: .getTransitionHandler().acceptsSource(
0266: (Activity) sourceActivity
0267: .getUserObject(),
0268: isExceptionalTrans)) {
0269: JOptionPane
0270: .showMessageDialog(
0271: getJaWEFrame(),
0272: getGraphController()
0273: .getSettings()
0274: .getLanguageDependentString(
0275: "WarningCannotAcceptMoreOutgoingTransitions"),
0276: getJaWEFrame().getAppTitle(),
0277: JOptionPane.INFORMATION_MESSAGE);
0278:
0279: return false;
0280: }
0281:
0282: return true;
0283: }
0284:
0285: return false;
0286: }
0287:
0288: /**
0289: * Returns <code>true</code> if parent cell of given port accepts source or target, depending
0290: * on <code>source</code> parameter.
0291: */
0292: public boolean validateConnection(
0293: GraphPortViewInterface pFirstPort,
0294: GraphPortViewInterface pSecondPort, Transition t) {
0295: // if ports are valid
0296: if (pFirstPort != null
0297: && pFirstPort.getCell() != null
0298: && (pFirstPort.getCell() instanceof GraphPortInterface)
0299: && pSecondPort != null
0300: && pSecondPort.getCell() != null
0301: && (pSecondPort.getCell() instanceof GraphPortInterface)) {
0302: // return if it accepts to be a source or a target
0303: GraphActivityInterface sourceActivity = pFirstPort
0304: .getGraphActivity();
0305: GraphActivityInterface targetActivity = pSecondPort
0306: .getGraphActivity();
0307: // System.out.println("Processing accept source for act "+sourceActivity+", target act="+targetActivity);
0308: if (!targetActivity.acceptsTarget()) {
0309: //System.err.println("acceptTarget = false");
0310: return false;
0311: }
0312:
0313: boolean isExceptionalTrans = XMLUtil
0314: .isExceptionalTransition(t)
0315: || getSubType().equals(
0316: JaWEConstants.TRANSITION_TYPE_EXCEPTION);
0317: // do not allow start-end connection
0318: if ((sourceActivity instanceof GraphBubbleActivityInterface)
0319: && (targetActivity instanceof GraphBubbleActivityInterface)) {
0320: JOptionPane
0321: .showMessageDialog(
0322: getJaWEFrame(),
0323: getGraphController()
0324: .getSettings()
0325: .getLanguageDependentString(
0326: "ErrorCannotConnectStartAndEnd"),
0327: getJaWEFrame().getAppTitle(),
0328: JOptionPane.ERROR_MESSAGE);
0329: return false;
0330: }
0331:
0332: Set targetActIncomingTrans = new HashSet();
0333: Set targetActNonExcTrans = new HashSet();
0334: Set targetActTrans = new HashSet();
0335: Set sourceActNonExcTrans = new HashSet();
0336: if (!(targetActivity instanceof GraphBubbleActivityInterface)) {
0337: targetActIncomingTrans
0338: .addAll(XMLUtil
0339: .getIncomingTransitions((Activity) targetActivity
0340: .getPropertyObject()));
0341: targetActTrans
0342: .addAll(XMLUtil
0343: .getOutgoingTransitions((Activity) targetActivity
0344: .getPropertyObject()));
0345: targetActNonExcTrans
0346: .addAll(XMLUtil
0347: .getNonExceptionalOutgoingTransitions((Activity) targetActivity
0348: .getPropertyObject()));
0349: }
0350: if (!(sourceActivity instanceof GraphBubbleActivityInterface)) {
0351: sourceActNonExcTrans
0352: .addAll(XMLUtil
0353: .getNonExceptionalOutgoingTransitions((Activity) sourceActivity
0354: .getPropertyObject()));
0355: }
0356: // if target is end bubble, do not allow connection if source is already connected
0357: // to another end bubble, or to some other activity except itself or if transition is exceptional one
0358: if (targetActivity instanceof GraphBubbleActivityInterface) { // must be end bubble in that case
0359: if (GraphManager.hasConnectedEndBubble(sourceActivity)
0360: || !(sourceActNonExcTrans.size() == 0 || (sourceActNonExcTrans
0361: .size() == 1 && JaWEManager
0362: .getInstance().getXPDLUtils()
0363: .hasCircularTransitions(
0364: sourceActNonExcTrans)))) {
0365: JOptionPane
0366: .showMessageDialog(
0367: getJaWEFrame(),
0368: getGraphController()
0369: .getSettings()
0370: .getLanguageDependentString(
0371: "ErrorEndingActivityCannotHaveOutgoingTransitions"),
0372: getJaWEFrame().getAppTitle(),
0373: JOptionPane.ERROR_MESSAGE);
0374: return false;
0375: }
0376:
0377: return true;
0378: }
0379:
0380: // if source is start bubble, do not allow connection if target is already connected
0381: // to another start bubble, or some other activity except itself
0382: if (sourceActivity instanceof GraphBubbleActivityInterface) { // must be start bubble in that case
0383: if (GraphManager
0384: .hasConnectedStartBubble(targetActivity)
0385: || !(targetActIncomingTrans.size() == 0 || (targetActIncomingTrans
0386: .size() == 1 && JaWEManager
0387: .getInstance().getXPDLUtils()
0388: .hasCircularTransitions(
0389: targetActIncomingTrans)))) {
0390: JOptionPane
0391: .showMessageDialog(
0392: getJaWEFrame(),
0393: getGraphController()
0394: .getSettings()
0395: .getLanguageDependentString(
0396: "ErrorStartingActivityCannotHaveIncomingTransitions"),
0397: getJaWEFrame().getAppTitle(),
0398: JOptionPane.ERROR_MESSAGE);
0399: return false;
0400: }
0401:
0402: if (!JaWEManager.getInstance().getTransitionHandler()
0403: .acceptsTarget(
0404: (Activity) targetActivity
0405: .getUserObject())) {
0406: JOptionPane
0407: .showMessageDialog(
0408: getJaWEFrame(),
0409: getGraphController()
0410: .getSettings()
0411: .getLanguageDependentString(
0412: "WarningCannotAcceptMoreIncomingTransitions"),
0413: getJaWEFrame().getAppTitle(),
0414: JOptionPane.WARNING_MESSAGE);
0415:
0416: return false;
0417: }
0418:
0419: return true;
0420: }
0421:
0422: boolean circularTransition = (sourceActivity == targetActivity);
0423: if (GraphManager.hasConnectedStartBubble(targetActivity)
0424: && !circularTransition) {
0425: JOptionPane
0426: .showMessageDialog(
0427: getJaWEFrame(),
0428: getGraphController()
0429: .getSettings()
0430: .getLanguageDependentString(
0431: "ErrorStartingActivityCannotHaveIncomingTransitions"),
0432: getJaWEFrame().getAppTitle(),
0433: JOptionPane.ERROR_MESSAGE);
0434: return false;
0435: }
0436:
0437: if (!(sourceActivity instanceof GraphBubbleActivityInterface)) {
0438: if (GraphManager.hasConnectedEndBubble(sourceActivity)
0439: && !(isExceptionalTrans || circularTransition)) {
0440: JOptionPane
0441: .showMessageDialog(
0442: getJaWEFrame(),
0443: getGraphController()
0444: .getSettings()
0445: .getLanguageDependentString(
0446: "ErrorEndingActivityCannotHaveOutgoingTransitions"),
0447: getJaWEFrame().getAppTitle(),
0448: JOptionPane.INFORMATION_MESSAGE);
0449:
0450: return false;
0451: }
0452: }
0453:
0454: Activity a = (Activity) sourceActivity.getUserObject();
0455: Activity b = (Activity) targetActivity.getUserObject();
0456: List status = new ArrayList(1);
0457:
0458: if (!JaWEManager.getInstance().getTransitionHandler()
0459: .allowsConnection(a, b, t, isExceptionalTrans,
0460: status)) {
0461: String errorMsg = "WarningSourceActivityCannotHaveMoreOutgoingTransitions";
0462: boolean isError = false;
0463: if (((Integer) status.get(0)).intValue() == 2) {
0464: errorMsg = "WarningTargetActivityCannotHaveMoreIncomingTransitions";
0465: } else if (((Integer) status.get(0)).intValue() == 3) {
0466: isError = true;
0467: errorMsg = "ErrorActivityCannotHaveMoreThenOneIncomingOutgoingTransitionFromToTheSameActivity";
0468: }
0469: JOptionPane.showMessageDialog(getJaWEFrame(),
0470: getGraphController().getSettings()
0471: .getLanguageDependentString(errorMsg),
0472: getJaWEFrame().getAppTitle(),
0473: isError ? JOptionPane.ERROR_MESSAGE
0474: : JOptionPane.INFORMATION_MESSAGE);
0475: return false;
0476: }
0477:
0478: return true;
0479: }
0480:
0481: return false;
0482: }
0483:
0484: protected GraphController getGraphController() {
0485: return graphController;
0486: }
0487:
0488: protected Graph getGraph() {
0489: return getGraphController().getSelectedGraph();
0490: }
0491:
0492: protected GraphManager getGraphManager() {
0493: return getGraph().getGraphManager();
0494: }
0495:
0496: protected JaWEController getJaWEController() {
0497: return JaWEManager.getInstance().getJaWEController();
0498: }
0499:
0500: protected JaWEFrame getJaWEFrame() {
0501: return getJaWEController().getJaWEFrame();
0502: }
0503:
0504: public boolean isSelectButtonSelected() {
0505: return mainType.equals(GraphEAConstants.SELECT_TYPE);
0506: }
0507:
0508: protected boolean isParticipantButtonSelected() {
0509: return mainType.equals(JaWEConstants.PARTICIPANT_TYPE);
0510: }
0511:
0512: protected boolean isActivityButtonSelected() {
0513: return mainType.equals(JaWEConstants.ACTIVITY_TYPE);
0514: }
0515:
0516: public boolean isTransitionButtonSelected() {
0517: return mainType.equals(JaWEConstants.TRANSITION_TYPE);
0518: }
0519:
0520: protected boolean isStartButtonSelected() {
0521: return mainType.equals(GraphEAConstants.START_TYPE);
0522: }
0523:
0524: protected boolean isEndButtonSelected() {
0525: return mainType.equals(GraphEAConstants.END_TYPE);
0526: }
0527:
0528: public void addPoint(Point p) {
0529: points.add(p);
0530: }
0531:
0532: public int getStatus() {
0533: if (isSelectButtonSelected()) {
0534: return JaWEGraphUI.SELECTION;
0535: } else if (isParticipantButtonSelected()) {
0536: return JaWEGraphUI.INSERT_PARTICIPANT;
0537: } else if (isTransitionButtonSelected()) {
0538: return JaWEGraphUI.INSERT_TRANSITION_START;
0539: } else {
0540: return JaWEGraphUI.INSERT_ELEMENT;
0541: }
0542: }
0543:
0544: public void setSelectionMode() {
0545: mainType = GraphEAConstants.SELECT_TYPE;
0546: subType = GraphEAConstants.SELECT_TYPE_DEFAULT;
0547:
0548: getGraph().setCursor(Cursor.getDefaultCursor());
0549: reset();
0550: }
0551:
0552: public void reset() {
0553: firstPort = null;
0554: port = null;
0555: start = null;
0556: current = null;
0557: getGraph().repaint();
0558:
0559: ((JaWEGraphUI) getGraph().getUI()).reset();
0560: }
0561:
0562: public void popupMenu(Point pPopupPoint) {
0563: double scale = getGraph().getScale();
0564: Point p = new Point();
0565: p.setLocation(pPopupPoint.getX() / scale, pPopupPoint.getY()
0566: / scale);
0567: Object cell = getGraph().getFirstCellForLocation(p.x, p.y);
0568: // needed for addPoint, etc.
0569: this .popupPoint = new Point(p);
0570: JPopupMenu menu = createPopupMenu(cell);
0571: menu.show(getGraph(), (int) pPopupPoint.getX(),
0572: (int) pPopupPoint.getY());
0573: }
0574:
0575: public void insertParticipant() {
0576: graphController.setUpdateInProgress(true);
0577: Participant toInsert = null;
0578: Participants pars = getGraph().getWorkflowProcess()
0579: .getParticipants();
0580: String idForVO = null;
0581: boolean insertIntoCollection = false;
0582: if (GraphEAConstants.PARTICIPANT_TYPE_FREE_TEXT_EXPRESSION
0583: .equals(subType)) {
0584: if (!getGraphManager()
0585: .isFreeTextExpressionParticipantShown()) {
0586: toInsert = FreeTextExpressionParticipant.getInstance();
0587: idForVO = toInsert.getId();
0588: setSelectionMode();
0589: } else {
0590: return;
0591: }
0592: } else if (GraphEAConstants.PARTICIPANT_TYPE_COMMON_EXPRESSION
0593: .equals(subType)) {
0594: toInsert = CommonExpressionParticipants.getInstance()
0595: .generateCommonExpressionParticipant(
0596: getGraph().getXPDLObject());
0597: idForVO = CommonExpressionParticipants.getInstance()
0598: .getIdForVisualOrderEA(toInsert.getId());
0599: } else {
0600: toInsert = JaWEManager.getInstance().getXPDLObjectFactory()
0601: .createXPDLObject(pars, subType, false);
0602: idForVO = toInsert.getId();
0603: insertIntoCollection = true;
0604: }
0605: JaWEManager.getInstance().getJaWEController()
0606: .startUndouableChange();
0607: if (insertIntoCollection) {
0608: pars.add(toInsert);
0609: }
0610: List vo = GraphUtilities.getParticipantVisualOrder(getGraph()
0611: .getXPDLObject());
0612: vo.add(idForVO);
0613: GraphUtilities.setParticipantVisualOrder(getGraph()
0614: .getXPDLObject(), vo);
0615: getGraphManager().insertParticipantAndArrangeParticipants(
0616: toInsert);
0617: List toSelect = new ArrayList();
0618: toSelect.add(toInsert);
0619: JaWEManager.getInstance().getJaWEController()
0620: .endUndouableChange(toSelect);
0621: graphController.setUpdateInProgress(false);
0622: // getGraph().selectParticipant(toInsert);
0623: graphController.adjustActions();
0624: }
0625:
0626: public void insertSpecialElement() {
0627: // if (isActivitySetButtonSelected()) {
0628: // Graph g = getGraph();
0629: // if (g != null) {
0630: // JaWEManager.getInstance().getJaWEController().startUndouableChange();
0631: // ActivitySets ass=g.getWorkflowProcess().getActivitySets();
0632: // ActivitySet as=JaWEManager.getInstance().getXPDLObjectFactory().createXPDLObject(ass,
0633: // getSelectedButtonType(), true);
0634: // JaWEManager.getInstance().getJaWEController().endUndouableChange();
0635: // }
0636: // }
0637: }
0638:
0639: public void insertElement(Point whereTo) {
0640: // if activity is selected
0641: if (isActivityButtonSelected()) {
0642: if (!getGraphManager().doesRootParticipantExist()) {
0643: JaWEFrame frame = JaWEManager.getInstance()
0644: .getJaWEController().getJaWEFrame();
0645: JOptionPane.showMessageDialog(frame,
0646: getGraphController().getSettings()
0647: .getLanguageDependentString(
0648: "WarningInvalidOperation"),
0649: frame.getAppTitle(),
0650: JOptionPane.WARNING_MESSAGE);
0651:
0652: } else {
0653: GraphParticipantInterface gpar = getGraphManager()
0654: .findParentActivityParticipantForLocation(
0655: whereTo, null, null);
0656: Point partLoc = getGraphManager().getBounds(gpar, null)
0657: .getBounds().getLocation();
0658: Point off = new Point(whereTo.x - partLoc.x, whereTo.y
0659: - partLoc.y);
0660: String partId = gpar.getPropertyObject().get("Id")
0661: .toValue();
0662: Activities acts = (Activities) getGraph()
0663: .getXPDLObject().get("Activities");
0664: Activity act = JaWEManager.getInstance()
0665: .getXPDLObjectFactory().createXPDLObject(acts,
0666: subType, false);
0667: GraphUtilities.setOffsetPoint(act, off);
0668: GraphUtilities.setParticipantId(act, partId);
0669: int acttype = act.getActivityType();
0670: if (acttype == XPDLConstants.ACTIVITY_TYPE_NO
0671: || acttype == XPDLConstants.ACTIVITY_TYPE_TOOL) {
0672: if (!partId.equals(FreeTextExpressionParticipant
0673: .getInstance().getId())) {
0674: act.setPerformer(partId);
0675: }
0676: }
0677: graphController.setUpdateInProgress(true);
0678: JaWEManager.getInstance().getJaWEController()
0679: .startUndouableChange();
0680: acts.add(act);
0681: getGraphManager().insertActivity(act);
0682: List toSelect = new ArrayList();
0683: toSelect.add(act);
0684: JaWEManager.getInstance().getJaWEController()
0685: .endUndouableChange(toSelect);
0686: getGraph().selectActivity(act, false);
0687: graphController.setUpdateInProgress(false);
0688: }
0689: }
0690:
0691: // if start button is selected
0692: else if (isStartButtonSelected()) {
0693: if (!getGraphManager().doesRootParticipantExist()) {
0694: JaWEFrame frame = JaWEManager.getInstance()
0695: .getJaWEController().getJaWEFrame();
0696: JOptionPane.showMessageDialog(frame,
0697: getGraphController().getSettings()
0698: .getLanguageDependentString(
0699: "WarningInvalidOperation"),
0700: frame.getAppTitle(),
0701: JOptionPane.WARNING_MESSAGE);
0702:
0703: } else {
0704: GraphParticipantInterface gpar = getGraphManager()
0705: .findParentActivityParticipantForLocation(
0706: whereTo, null, null);
0707: Point partLoc = getGraphManager().getBounds(gpar, null)
0708: .getBounds().getLocation();
0709: Point offset = new Point(whereTo.x - partLoc.x,
0710: whereTo.y - partLoc.y);
0711: String partId = gpar.getPropertyObject().get("Id")
0712: .toValue();
0713: graphController.setUpdateInProgress(true);
0714: JaWEManager.getInstance().getJaWEController()
0715: .startUndouableChange();
0716: ExtendedAttribute ea = GraphUtilities
0717: .createStartOrEndExtendedAttribute(getGraph()
0718: .getXPDLObject(), true, partId, offset,
0719: subType, true);
0720: getGraphManager().insertStart(ea);
0721: List toSelect = new ArrayList();
0722: toSelect.add(ea);
0723: JaWEManager.getInstance().getJaWEController()
0724: .endUndouableChange(toSelect);
0725: getGraph().selectBubble(ea, false);
0726: graphController.setUpdateInProgress(false);
0727: }
0728: }
0729:
0730: // if end button is selected
0731: if (isEndButtonSelected()) {
0732: if (!getGraphManager().doesRootParticipantExist()) {
0733: JaWEFrame frame = JaWEManager.getInstance()
0734: .getJaWEController().getJaWEFrame();
0735: JOptionPane.showMessageDialog(frame,
0736: getGraphController().getSettings()
0737: .getLanguageDependentString(
0738: "WarningInvalidOperation"),
0739: frame.getAppTitle(),
0740: JOptionPane.WARNING_MESSAGE);
0741:
0742: } else {
0743: GraphParticipantInterface gpar = getGraphManager()
0744: .findParentActivityParticipantForLocation(
0745: whereTo, null, null);
0746: Point partLoc = getGraphManager().getBounds(gpar, null)
0747: .getBounds().getLocation();
0748: Point offset = new Point(whereTo.x - partLoc.x,
0749: whereTo.y - partLoc.y);
0750: String partId = gpar.getPropertyObject().get("Id")
0751: .toValue();
0752: graphController.setUpdateInProgress(true);
0753: JaWEManager.getInstance().getJaWEController()
0754: .startUndouableChange();
0755: ExtendedAttribute ea = GraphUtilities
0756: .createStartOrEndExtendedAttribute(getGraph()
0757: .getXPDLObject(), false, partId,
0758: offset, subType, true);
0759: getGraphManager().insertEnd(ea);
0760: List toSelect = new ArrayList();
0761: toSelect.add(ea);
0762: JaWEManager.getInstance().getJaWEController()
0763: .endUndouableChange(toSelect);
0764: getGraph().selectBubble(ea, false);
0765: graphController.setUpdateInProgress(false);
0766: }
0767: }
0768: }
0769:
0770: public boolean insertTransitionFirstPort(
0771: GraphPortViewInterface pPort) {
0772: if (pPort != null) {
0773: if (firstPort == null) {
0774: // start the transition only if start is valid
0775: // System.out.println("POINTED TO ACT" + ((GraphPortInterface) (port).getCell()).getActivity());
0776: if (validateSource(pPort)) {
0777: points = new Vector();
0778: firstPort = pPort;
0779: double scale = getGraph().getScale();
0780: start = firstPort.getBounds().getBounds()
0781: .getLocation();// HM, JGraph3.4.1
0782: start.x += firstPort.getPortSize().width / 2;
0783: start.y += firstPort.getPortSize().height / 2;
0784: start = new Point((int) (start.getX() * scale),
0785: (int) (start.getY() * scale));
0786:
0787: return true;
0788: }
0789: }
0790: }
0791:
0792: return false;
0793: }
0794:
0795: public boolean insertTransitionSecondPort(
0796: GraphPortViewInterface pPort) {
0797: if (pPort != null) {
0798: // normal
0799: if (pPort != firstPort) {
0800: if (validateConnection(firstPort, pPort, null)) {
0801: GraphActivityInterface s = ((GraphPortInterface) firstPort
0802: .getCell()).getActivity();
0803: GraphActivityInterface t = ((GraphPortInterface) pPort
0804: .getCell()).getActivity();
0805: XMLElement sxpdl = s.getPropertyObject();
0806: XMLElement txpdl = t.getPropertyObject();
0807: if (sxpdl instanceof Activity
0808: && txpdl instanceof Activity) {
0809: Transitions tras = (Transitions) getGraph()
0810: .getXPDLObject().get("Transitions");
0811: String fromId = ((Activity) sxpdl).getId();
0812: String toId = ((Activity) txpdl).getId();
0813: Transition tra = JaWEManager.getInstance()
0814: .getXPDLObjectFactory()
0815: .createXPDLObject(tras, subType, false);
0816: tra.setFrom(fromId);
0817: tra.setTo(toId);
0818: if (fromId.equals(toId)) {
0819: GraphUtilities
0820: .setStyle(
0821: tra,
0822: GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_BEZIER);
0823: } else {
0824: GraphUtilities
0825: .setStyle(
0826: tra,
0827: getGraphController()
0828: .getGraphSettings()
0829: .getDefaultTransitionStyle());
0830: }
0831: GraphUtilities.setBreakpoints(tra, points);
0832: points.clear();
0833: graphController.setUpdateInProgress(true);
0834: JaWEManager.getInstance().getJaWEController()
0835: .startUndouableChange();
0836: tras.add(tra);
0837: getGraphManager().insertTransition(tra);
0838: List toSelect = new ArrayList();
0839: toSelect.add(tra);
0840: JaWEManager.getInstance().getJaWEController()
0841: .endUndouableChange(toSelect);
0842: getGraph().selectTransition(tra, false);
0843: graphController.setUpdateInProgress(false);
0844: } else if (sxpdl instanceof ExtendedAttribute
0845: && txpdl instanceof Activity) {
0846: connectStartOrEndBubble(
0847: (ExtendedAttribute) sxpdl,
0848: ((Activity) txpdl).getId());
0849: } else if (txpdl instanceof ExtendedAttribute
0850: && sxpdl instanceof Activity) {
0851: connectStartOrEndBubble(
0852: (ExtendedAttribute) txpdl,
0853: ((Activity) sxpdl).getId());
0854: }
0855: return true;
0856: }
0857: // circular
0858: } else {
0859: if (validateConnection(pPort, pPort, null)) {
0860: Point realP = (Point) getGraph().fromScreen(
0861: new Point(start));
0862: List breakpoints = new ArrayList();
0863: if (points.size() == 0) {
0864: int rp50x1 = realP.x - 50;
0865: int rp50x2 = realP.x + 50;
0866: if (rp50x1 < 0) {
0867: rp50x2 = rp50x2 - rp50x1;
0868: rp50x1 = 0;
0869: }
0870: int rp50y = realP.y - 50;
0871: if (rp50y < 0)
0872: rp50y = realP.y + 50;
0873:
0874: breakpoints.add(new Point(Math.abs(rp50x1),
0875: Math.abs(rp50y)));
0876: breakpoints.add(new Point(Math.abs(rp50x2),
0877: Math.abs(rp50y)));
0878: } else {
0879: breakpoints.addAll(points);
0880: points.clear();
0881: }
0882:
0883: Activity act = (Activity) ((GraphPortInterface) firstPort
0884: .getCell()).getActivity()
0885: .getPropertyObject();
0886:
0887: Transitions tras = (Transitions) getGraph()
0888: .getXPDLObject().get("Transitions");
0889: Transition tra = JaWEManager.getInstance()
0890: .getXPDLObjectFactory().createXPDLObject(
0891: tras, subType, false);
0892: tra.setFrom(act.getId());
0893: tra.setTo(act.getId());
0894: GraphUtilities
0895: .setStyle(
0896: tra,
0897: GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_BEZIER);
0898: GraphUtilities.setBreakpoints(tra, breakpoints);
0899: getGraphController().setUpdateInProgress(true);
0900: JaWEManager.getInstance().getJaWEController()
0901: .startUndouableChange();
0902: tras.add(tra);
0903: getGraphManager().insertTransition(tra);
0904: List toSelect = new ArrayList();
0905: toSelect.add(tra);
0906: JaWEManager.getInstance().getJaWEController()
0907: .endUndouableChange(toSelect);
0908: getGraph().selectTransition(tra, false);
0909: getGraphController().setUpdateInProgress(false);
0910:
0911: return true;
0912: }
0913: }
0914: }
0915:
0916: return false;
0917: }
0918:
0919: public void overlay(JGraph graph, Graphics g, boolean clear) {
0920: super .overlay(graph, g, clear);
0921: if (getGraph() != null) {
0922: paintPort(getGraph().getGraphics());
0923: }
0924: if (start != null) {
0925: if (isTransitionButtonSelected()) {
0926: drawTransition(g);
0927: }
0928: }
0929: }
0930:
0931: protected void drawTransition(MouseEvent ev) {
0932: Graphics g = getGraph().getGraphics();
0933: Color bg = getGraph().getBackground();
0934: Color fg = graphController.getGraphSettings()
0935: .getBubbleConectionColor();
0936: g.setColor(fg);
0937: g.setXORMode(bg);
0938: overlay(getGraph(), g, false);
0939: current = (Point) getGraph().snap(ev.getPoint());
0940: double scale = getGraph().getScale();
0941: port = (GraphPortViewInterface) getGraph().getPortViewAt(
0942: ev.getX(), ev.getY());
0943: if (port != null) {
0944: current = port.getBounds().getBounds().getLocation();//HM, JGraph3.4.1
0945: //current=lastPort.getLocation(null);
0946: current = new Point((int) (current.x * scale),
0947: (int) (current.y * scale));
0948: current.x += port.getPortSize().width / 2;
0949: current.y += port.getPortSize().height / 2;
0950:
0951: }
0952: g.setColor(bg);
0953: g.setXORMode(fg);
0954: overlay(getGraph(), g, false);
0955: }
0956:
0957: protected void drawTransition(Graphics g) {
0958: Point l = start;
0959: if (points.size() != 0)
0960: l = (Point) points.get(points.size() - 1);
0961: if (current != null) {
0962: g.drawLine(l.x, l.y, current.x, current.y);
0963: }
0964: }
0965:
0966: protected void paintPort(Graphics g) {
0967: if (port != null) {
0968: boolean offset = (GraphConstants.getOffset(port
0969: .getAttributes()) != null);
0970: Rectangle r = (offset) ? port.getBounds().getBounds()//HM, JGraph3.4.1
0971: : port.getParentView().getBounds().getBounds();//HM, JGraph3.4.1
0972: r = (Rectangle) getGraph().toScreen(new Rectangle(r));//HM, JGraph3.4.1
0973: int s = 3;
0974: r.translate(-s, -s);
0975: r.setSize(r.width + 2 * s, r.height + 2 * s);
0976: JaWEGraphUI ui = (JaWEGraphUI) getGraph().getUI();
0977: ui.paintCell(g, port, r, true);
0978: }
0979: }
0980:
0981: public void connectStartOrEndBubble(ExtendedAttribute sea,
0982: String actId) {
0983: GraphBubbleActivityInterface gactb = getGraphManager()
0984: .getBubble(sea);
0985: if (gactb != null) {
0986: GraphTransitionInterface gtra = getGraphManager()
0987: .connectStartOrEndBubble(gactb, actId);
0988: if (gtra != null) {
0989: getGraphController().setUpdateInProgress(true);
0990: JaWEManager.getInstance().getJaWEController()
0991: .startUndouableChange();
0992: StartEndDescription sed = gactb
0993: .getStartEndDescription();
0994: sed.setActId(actId);
0995: sea.setVValue(sed.toString());
0996: List toSelect = new ArrayList();
0997: toSelect.add(getGraph().getXPDLObject());
0998: JaWEManager.getInstance().getJaWEController()
0999: .endUndouableChange(toSelect);
1000: getGraph().clearSelection();
1001: getGraphController().setUpdateInProgress(false);
1002: }
1003: }
1004: }
1005:
1006: public String getMainType() {
1007: return mainType;
1008: }
1009:
1010: public String getSubType() {
1011: return subType;
1012: }
1013:
1014: public void setType(String mainType, String subType, Cursor cursor) {
1015: this.mainType = mainType;
1016: this.subType = subType;
1017:
1018: if (cursor != null)
1019: getGraph().setCursor(cursor);
1020: else
1021: getGraph().setCursor(Cursor.getDefaultCursor());
1022:
1023: reset();
1024: }
1025: }
|