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.FigEdge;
030    
031    import se.liu.ida.critiquer.activities.Activity;
032    
033    public class OrderingEdge extends NetEdge {
034    
035            /**
036         * 
037         */
038            private static final long serialVersionUID = 1L;
039    
040            private OrderingFigEdge   figEdge;
041    
042            private PreviousPort      previousPort   = null;
043    
044            private NextPort                  nextPort               = null;
045    
046            private Activity                  beforeActivity;
047    
048            private Activity                  afterActivity;
049    
050            public OrderingEdge() {
051                    super();
052                    // TODO Auto-generated constructor stub
053            }
054    
055            @Override
056            public FigEdge makePresentation(Layer lay) {
057                    if (figEdge == null) {
058                            figEdge = new OrderingFigEdge();
059                            figEdge.setDashed(true);
060    
061                    }
062                    return figEdge;
063            }
064    
065            /**
066         * 
067         * <p>
068         * Just as in the case with inheritance ports, the nextPort denotes the port
069         * connecting TO the next activity.
070         * </p>
071         * <p>
072         * That means that the nextPort is connected to a Fig that represents the
073         * activitiy that should come <b>before</b>.
074         * </p>
075         * 
076         * 
077         */
078            @Override
079            public boolean connect(GraphModel gm, Object srcPort, Object destPort) {
080                    boolean connect = super.connect(gm, srcPort, destPort);
081                    if (srcPort instanceof PreviousPort && destPort instanceof NextPort) {
082                            previousPort = (PreviousPort) srcPort;
083                            nextPort = (NextPort) destPort;
084                    } else if (destPort instanceof PreviousPort && srcPort instanceof NextPort) {
085                            previousPort = (PreviousPort) destPort;
086                            nextPort = (NextPort) srcPort;
087                    } else {
088                            System.err.println("Cannot connect " + srcPort.getClass().getSimpleName()
089                                                               + " and "
090                                                               + destPort.getClass().getSimpleName()
091                                                               + " with OrderingEdge");
092                            connect = false;
093                    }
094                    if (connect) {
095                            beforeActivity = nextPort.getActivityNode().getActivity();
096                            afterActivity = previousPort.getActivityNode().getActivity();
097                            beforeActivity.order(afterActivity);
098                    }
099                    return connect;
100            }
101    
102            /**
103         * 
104         * @see se.liu.ida.critiquer.gui.graph.OrderingEdge#connect(org.tigris.gef.graph.GraphModel,java.lang.Object,java.lang.Object)
105         *      for information on what the ports denote
106         * 
107         */
108            @Override
109            public void deleteFromModel() {
110                    super.deleteFromModel();
111                    nextPort.getActivityNode().getActivity().removeOrder(previousPort.getActivityNode()
112                                                                                                                                                                                    .getActivity());
113            }
114    
115            @Override
116            public String getId() {
117                    // TODO Auto-generated method stub
118                    return null;
119            }
120    
121            /**
122         * @return Returns the afterActivity.
123         */
124            public Activity getAfterActivity() {
125                    return afterActivity;
126            }
127    
128            /**
129         * @return Returns the beforeActivity.
130         */
131            public Activity getBeforeActivity() {
132                    return beforeActivity;
133            }
134    
135    }