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 java.io.PrintStream; 027 import java.lang.reflect.Constructor; 028 import java.lang.reflect.InvocationTargetException; 029 import java.util.Hashtable; 030 031 import org.tigris.gef.base.Layer; 032 import org.tigris.gef.graph.presentation.NetNode; 033 import org.tigris.gef.presentation.FigNode; 034 035 import se.liu.ida.critiquer.activities.Activity; 036 import se.liu.ida.critiquer.activities.ActivityUtils; 037 038 public class ActivityNode extends NetNode { 039 040 /** 041 * 042 */ 043 private static final long serialVersionUID = 1L; 044 045 public static PrintStream debug = System.err; 046 047 private Activity activity; 048 049 private ParentPort parentPort; 050 051 private ChildPort childPort; 052 053 private PreviousPort previousPort; 054 055 private NextPort nextPort; 056 057 private transient ActivityFigNode fn; 058 059 public ActivityNode(Class activityClass) { 060 if (Activity.class.isAssignableFrom(activityClass)) { 061 try { 062 Constructor constructor = activityClass 063 .getConstructor(new Class[] { Activity.class }); 064 activity = (Activity) constructor 065 .newInstance(new Object[] { null }); 066 } catch (SecurityException e) { 067 // TODO Auto-generated catch block 068 e.printStackTrace(); 069 } catch (IllegalArgumentException e) { 070 // TODO Auto-generated catch block 071 e.printStackTrace(); 072 } catch (NoSuchMethodException e) { 073 // TODO Auto-generated catch block 074 e.printStackTrace(); 075 } catch (InstantiationException e) { 076 // TODO Auto-generated catch block 077 e.printStackTrace(); 078 } catch (IllegalAccessException e) { 079 // TODO Auto-generated catch block 080 e.printStackTrace(); 081 } catch (InvocationTargetException e) { 082 debug.println("ActivityNode: Constructor for "+activityClass.getSimpleName()+" threw exception " 083 + e.getCause().getMessage()); 084 debug.println("Stack trace of cause: "); 085 e.getCause().printStackTrace(debug); 086 087 } 088 } else { 089 debug.println("Trying to initialize non-activity class: " 090 + activityClass.getSimpleName()); 091 } 092 093 } 094 095 @Override 096 public void initialize(Hashtable args) { 097 parentPort = new ParentPort(this); 098 childPort = new ChildPort(this); 099 previousPort = new PreviousPort(this); 100 nextPort = new NextPort(this); 101 addPort(parentPort); 102 addPort(childPort); 103 addPort(previousPort); 104 addPort(nextPort); 105 } 106 107 @Override 108 public FigNode makePresentation(Layer lay) { 109 if (fn == null) { 110 fn = new ActivityFigNode(this); 111 } 112 return fn; 113 } 114 115 @Override 116 public String getId() { 117 // TODO Auto-generated method stub 118 return null; 119 } 120 121 /** 122 * @return Returns the childPort. 123 */ 124 public ChildPort getChildPort() { 125 return childPort; 126 } 127 128 /** 129 * @return Returns the nextPort. 130 */ 131 public NextPort getNextPort() { 132 return nextPort; 133 } 134 135 /** 136 * @return Returns the parentPort. 137 */ 138 public ParentPort getParentPort() { 139 return parentPort; 140 } 141 142 /** 143 * @return Returns the previousPort. 144 */ 145 public PreviousPort getPreviousPort() { 146 return previousPort; 147 } 148 149 /** 150 * @return Returns the activity. 151 */ 152 public Activity getActivity() { 153 return activity; 154 } 155 156 /* 157 * (non-Javadoc) 158 * 159 * @see java.lang.Object#toString() 160 */ 161 @Override 162 public String toString() { 163 return activity.toString(); 164 } 165 166 /** 167 * Restore necessary properties after reading this node from a file 168 */ 169 public void postLoad() { 170 // Restore the graphical representation 171 fn = new ActivityFigNode(this); 172 getActivity().postLoad(); 173 } 174 175 public void preSave() { 176 getActivity().preSave(); 177 } 178 179 /** 180 * 181 * Remove the activity, along with any constraints related to it and notify listeners it has been removed. 182 * @see org.tigris.gef.graph.presentation.NetNode#deleteFromModel() 183 */ 184 @Override 185 public void deleteFromModel() { 186 super.deleteFromModel(); 187 ActivityUtils.removeConstraintsForActivity(getActivity()); 188 getActivity().signalActivityRemoved(); 189 } 190 191 }