1 4 package org.oddjob.monitor.model; 5 6 import java.util.Observable ; 7 8 import org.apache.log4j.Logger; 9 import org.oddjob.Stateful; 10 import org.oddjob.logging.ConsoleArchiver; 11 import org.oddjob.logging.LogArchiver; 12 import org.oddjob.logging.LogLevel; 13 import org.oddjob.state.JobStateEvent; 14 import org.oddjob.state.JobStateListener; 15 16 public class DetailModel extends Observable { 17 private static final Logger logger = Logger.getLogger(DetailModel.class); 18 19 public static final int STATE_TAB = 0; 20 public static final int CONSOLE_TAB = 1; 21 public static final int LOG_TAB = 2; 22 public static final int PROPERTIES_TAB = 3; 23 24 25 private int tabSelected = STATE_TAB; 26 27 28 private Object selectedJob; 29 30 31 private final LogModel consoleModel = new LogModel(); 32 33 34 private final LogModel logModel = new LogModel(); 35 36 37 private PropertyModel propertyModel = new PropertyModel(); 38 39 40 private final StateModel stateModel = new StateModel(); 41 42 43 private final JobStateListener stateListener = new JobStateListener() { 44 public void jobStateChange(JobStateEvent event) { 45 stateModel.change(event); 46 } 47 }; 48 49 54 public LogModel getConsoleModel() { 55 return consoleModel; 56 } 57 58 63 public LogModel getLogModel() { 64 return logModel; 65 } 66 67 72 public PropertyModel getPropertyModel() { 73 return propertyModel; 74 } 75 76 81 public void setTabSelected(int tabSelected) { 82 this.tabSelected = tabSelected; 83 } 84 85 90 public int getTabSelected() { 91 return tabSelected; 92 } 93 94 100 public void deSelect(ExplorerContext context, Object old) { 101 logger.debug("DeSelected node [" + old + "]"); 102 selectedJob = null; 103 104 stateModel.clear(); 106 if (old instanceof Stateful) { 107 ((Stateful) old).removeJobStateListener(stateListener); 108 } 109 110 ConsoleArchiver consoleArchiver = context.getConsoleArchiver(); 112 consoleArchiver.removeConsoleListener(consoleModel, old); 113 consoleModel.setClear(); 114 115 LogArchiver logArchiver = context.getLogArchiver(); 117 logArchiver.removeLogListener(logModel, old); 118 logModel.setClear(); 119 120 setChanged(); 121 notifyObservers(context); 122 } 123 124 130 public void select(ExplorerContext context, Object job) { 131 logger.debug("Selected node [" + job + "]"); 132 selectedJob = job; 133 134 if (tabSelected == STATE_TAB) { 135 if (job instanceof Stateful) { 137 ((Stateful) job).addJobStateListener(stateListener); 138 } 139 } 140 else if (tabSelected == CONSOLE_TAB) { 141 ConsoleArchiver consoleArchiver = context.getConsoleArchiver(); 142 consoleArchiver.addConsoleListener(consoleModel, job, -1, 1000); 143 } 144 else if (tabSelected == LOG_TAB) { 145 LogArchiver logArchiver = context.getLogArchiver(); 147 logArchiver.addLogListener(logModel, job, LogLevel.DEBUG, -1, 1000); 148 } 149 150 setChanged(); 151 notifyObservers(context); 152 } 153 154 159 public Object getSelectedJob() { 160 return selectedJob; 161 } 162 163 168 public Observable getStateModel() { 169 return stateModel; 170 } 171 172 } 173 | Popular Tags |