001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.gui.graph; 025 026 import org.tigris.gef.base.Layer; 027 import org.tigris.gef.graph.GraphModel; 028 import org.tigris.gef.graph.presentation.NetEdge; 029 import org.tigris.gef.presentation.ArrowHeadTriangle; 030 import org.tigris.gef.presentation.FigEdge; 031 032 import se.liu.ida.critiquer.activities.Activity; 033 034 public class InheritanceEdge extends NetEdge { 035 036 /** 037 * 038 */ 039 private static final long serialVersionUID = 1L; 040 041 private InheritanceFigEdge edge; 042 043 private ChildPort childPort; 044 045 private ParentPort parentPort; 046 047 private Activity child; 048 049 private Activity parent; 050 051 public InheritanceEdge() { 052 super(); 053 // TODO Auto-generated constructor stub 054 } 055 056 @Override 057 public FigEdge makePresentation(Layer lay) { 058 if (edge == null) { 059 edge = new InheritanceFigEdge(); 060 if (getSourcePort() instanceof ChildPort) { 061 // Drawing edge from child to parent 062 edge.setDestArrowHead(new ArrowHeadTriangle()); 063 064 } else if (getSourcePort() instanceof ParentPort) { 065 // Drawing edge from parent to child 066 edge.setSourceArrowHead(new ArrowHeadTriangle()); 067 068 } 069 } 070 return edge; 071 } 072 073 /** 074 * 075 * The parentPort is the port that connects TO a parent and the childPort is 076 * the port that connects TO the children. 077 * 078 * That means that a parentPort is located on an ActivityFigNode which 079 * represents and activity that is supposed to be the child of the activity 080 * associated with the childPort. 081 * 082 */ 083 @Override 084 public boolean connect(GraphModel gm, Object srcPort, Object destPort) { 085 boolean connect = super.connect(gm, srcPort, destPort); 086 childPort = null; 087 parentPort = null; 088 if (srcPort instanceof ChildPort && destPort instanceof ParentPort) { 089 childPort = (ChildPort) srcPort; 090 parentPort = (ParentPort) destPort; 091 } else if (destPort instanceof ChildPort && srcPort instanceof ParentPort) { 092 childPort = (ChildPort) destPort; 093 parentPort = (ParentPort) srcPort; 094 } else { 095 System.err.println("Cannot connect " + srcPort.getClass().getSimpleName() 096 + " and " 097 + destPort.getClass().getSimpleName() 098 + " with an InheritanceEdge"); 099 connect = false; 100 } 101 if (connect) { 102 child = parentPort.getActivityNode().getActivity(); 103 parent = childPort.getActivityNode().getActivity(); 104 child.initParentRelationship(parent); 105 } 106 107 return connect; 108 109 } 110 111 /** 112 * @see se.liu.ida.critiquer.gui.graph.InheritanceEdge#connect(org.tigris.gef.graph.GraphModel,java.lang.Object,java.lang.Object) 113 * for an explanation on how the parentPort should be interpreted. 114 */ 115 @Override 116 public void deleteFromModel() { 117 super.deleteFromModel(); 118 parentPort.getActivityNode().getActivity().endParentRelationship(); 119 } 120 121 @Override 122 public String getId() { 123 // TODO Auto-generated method stub 124 return null; 125 } 126 127 /** 128 * @return Returns the child. 129 */ 130 public Activity getChild() { 131 return child; 132 } 133 134 /** 135 * @return Returns the parent. 136 */ 137 public Activity getParent() { 138 return parent; 139 } 140 141 }