public ProcessDashboard(String location, String title) {
super();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(this);
ProfTimer pt = new ProfTimer(ProcessDashboard.class, "ProcessDashboard");
// adjust the working directory if necessary.
if (location == null)
location = maybeFollowDataDirLinkFile();
configureWorkingDirectory(location);
// load app defaults and user settings.
try {
InternalSettings.initialize("");
} catch (Exception e) {
logErr("Unable to read settings file", e);
displayStartupIOError("Errors.Read_File_Error.Settings_File",
e.getMessage(), e);
System.exit(0);
}
propertiesFile = Settings.getFile("stateFile");
File prop_file = new File(propertiesFile);
try {
prop_file = prop_file.getCanonicalFile();
} catch (IOException ioe) {}
propertiesFile = prop_file.getPath();
property_directory = prop_file.getParent() + Settings.sep;
TemplateLoader.resetTemplateURLs();
configureSystemPropertiesFromSettings();
pt.click("Read settings");
DefectAnalyzer.setDataDirectory(property_directory);
CmsDefaultConfig.setPersistenceDirectories(
getCmsPersistenceDirs(prop_file.getParentFile()));
ExternalResourceManager.getInstance().setDashboardContext(this);
ExternalResourceManager.getInstance().initializeMappings(
prop_file.getParentFile());
try {
default_directory = prop_file.getParentFile().getCanonicalPath();
} catch (IOException ioe) {
default_directory = prop_file.getParentFile().getAbsolutePath();
}
ImportDirectoryFactory.getInstance().setBaseDirectory(
new File(default_directory));
pt.click("Set default directory");
// configure the writability of the data and lock if applicable
maybeSetupHistoricalMode();
maybeEnableReadOnlyMode();
pt.click("Checked read only mode");
if (!Settings.isReadOnly()) {
tryToLockDataForWriting();
pt.click("Tried to acquire write lock");
}
// check for a dataset migration import request
DatasetAutoMigrator.maybeRun(workingDirectory,
new DatasetAutoMigrator.DialogParentSource() {
public Component getDialogParent() { return hideSS(); }});
// run the backup process as soon as possible
fileBackupManager = new FileBackupManager(workingDirectory);
fileBackupManager.maybeRun(FileBackupManager.STARTUP, null);
pt.click("Ran file backup");
// start the http server.
try {
int httpPort = Settings.getInt(HTTP_PORT_SETTING, DEFAULT_WEB_PORT);
webServer = new WebServer(httpPort);
webServer.setDashboardContext(this);
InternalSettings.addPropertyChangeListener
(HTTP_PORT_SETTING, new HttpPortSettingListener());
ScriptID.setNameResolver(new ScriptNameResolver(webServer));
} catch (IOException ioe) {
logErr("Couldn't start web server", ioe);
}
pt.click("Started web server");
// create the data repository.
data = new DataRepository();
if ("true".equalsIgnoreCase(Settings.getVal("dataFreezing.disabled")))
data.disableFreezing();
data.addGlobalDefineDeclarations("#define AUTO_INDIV_ROOT_TAG t");
pt.click("Created Data Repository");
templates = TemplateLoader.loadTemplates(data);
pt.click("Loaded templates");
DataVersionChecker.ensureVersionsOrExit();
aum = new AutoUpdateManager(TemplateLoader.getPackages());
resources = Resources.getDashBundle("ProcessDashboard");
InternalSettings.loadLocaleSpecificDefaults(resources);
FormatUtil.setDateFormats(Settings.getVal("dateFormat"),
Settings.getVal("dateTimeFormat"));
Translator.init();
LookAndFeelSettings.loadLocalizedSettings();
pt.click("Set locale specific defaults");
data.setDatafileSearchURLs(TemplateLoader.getTemplateURLs());
pt.click("Set datafile search URLs");
versionNumber = TemplateLoader.getPackageVersion("pspdash"); // legacy
logger.info("Process Dashboard version " + versionNumber);
setupWindowTitle(title);
// initialize the content roots for the http server.
webServer.setRoots(TemplateLoader.getTemplateURLs());
WebServer.setOutputCharset(getWebCharset());
pt.click("Set web server roots");
BetaVersionSetup.runSetup(property_directory);
pt.click("Ran beta version setup");
// determine if corrupt Data Files are present in the pspdata directory
// and take steps to repair them.
brokenData = new BrokenDataFileHandler();
brokenData.findCorruptFiles(property_directory);
pt.click("Checked for lost data files");
if (brokenData.repairCorruptFiles(this) == false) {
// if the lost data files could not be repaired, exit the dashboard
logger.severe
("Dashboard was terminated due to user request. " +
"The following bad data files were found in the "+
"psp data directory:\n" + brokenData.getCorruptFileStr());
System.exit(0);
}
// open and load the the user's work breakdown structure
props = new DashHierarchy(property_directory);
Vector v = null;
Exception saxException = null;
if (prop_file.exists()) {
try {
// try to load the user's existing properties file.
try {
v = props.loadXML(propertiesFile, templates);
} catch (Exception se1) {
if (!safeInstanceof(se1, "org.xml.sax.SAXException"))
throw se1;
saxException = se1;
props.load(propertiesFile);
LegacySupport.fixupV13ScriptIDs(props);
props.saveXML(propertiesFile, null);
props.clear();
v = props.loadXML(propertiesFile, templates);
}
} catch (Exception e) {
// this is a serious problem, indicating a corrupt
// state file. Display a warning to the user, then exit.
if (saxException != null) e = saxException;
propertiesFile = prop_file.getAbsolutePath();
try {
propertiesFile = prop_file.getCanonicalPath();
} catch (Exception e2) {}
DashHierarchy.displayCorruptStateFileWarning
(resources, propertiesFile, e);
System.exit(0);
}
} else {
try {
// apparently, the user doesn't already have a properties
// file. read the default properties file, which simply
// contains nodes for "Project" and "Non Project".
String state = new String
(FileUtils.slurpContents(getClass().getResourceAsStream
(DEFAULT_PROP_FILE), true),
"ISO-8859-1");
// localize the strings "Project" and "Non Project"
state = StringUtils.findAndReplace
(state, "<Project>",
"<"+resources.getString("Project")+">");
state = StringUtils.findAndReplace
(state, "<Non Project>",
"<"+resources.getString("Non_Project")+">");
v = props.load(new StringReader(state), true);
// Starting with version UTF8_SUPPORT_VERSION, all new datasets
// use UTF-8 for datafiles and XML for defects.
DataRepository.enableUtf8Encoding();
DefectLog.enableXmlStorageFormat();
if (Settings.isTeamMode() == false)
displayFirstTimeUserHelp();
} catch (Exception e) {
logErr("Couldn't read default state file", e);
}
}
data.setNodeComparator(props);
registerHierarchyDataElement();
data.pinElement(DashHierarchy.DATA_REPOSITORY_NAME);
activeTaskModel = new DefaultActiveTaskModel(props);
pt.click("Loaded dashboard hierarchy");
// Make certain we know whether this dashboard is operating as a
// team dashboard or a personal dashboard.
configureTeamOrPersonalDatasetMode();
// create the database plugin
if (createDatabasePlugin())
pt.click("Created and started the database plugin");
// create the time log
try {
this.timeLog = new DashboardTimeLog(new File(property_directory), data, props);
this.timeLog.getTimeLoggingModel().setActiveTaskModel(activeTaskModel);
DashboardTimeLog.setDefault(this.timeLog);
} catch (IOException e1) {
logErr("Unable to read time log", e1);
displayStartupIOError("Errors.Read_File_Error.Time_Log",
property_directory + WorkingTimeLog.TIME_LOG_FILENAME, e1);
System.exit(0);
}
pt.click("Initialized time log");
// possibly reload cached data definitions.
File serializedDefinitions = new File(property_directory, "defns.ser");
if (serializedDefinitions.exists() &&
(serializedDefinitions.lastModified() >
TemplateLoader.getTemplateTimestamp()))
try {
data.loadDefinitions(new FileInputStream
(serializedDefinitions));
} catch (Exception e) {}
// open all the datafiles that were specified in the properties file.
data.startInconsistency();
try {
if (v != null) {
String a[];
for (int i = 0; i < v.size(); i++) {
a = (String[])v.elementAt (i);
openDatafile(a[0], a[1]);
}
}
}catch (Exception e) { logErr("open datafiles failed!", e); };
// open the global data file.
try {
data.openDatafile("", property_directory + "global.dat");
} catch (FileNotFoundException exc) {
// if the user doesn't have a global data file, create one
// for them from the default template.
HierarchyEditor.createDataFile (property_directory + "global.dat",
"dataFile.txt", null);
openDatafile("", "global.dat");
} catch (Exception exc) {
logErr("when generating default datafile, caught exception", exc);
}
registerEnvironmentalData();
pt.click("Opened data files");
data.fixMisparentedData();
pt.click("Fixed misparented data");
timeLog.setTimingForbiddenPaths(getBrokenDataPaths());
SizeEstimatingTemplate.migrateLegacyData(props, data);
try {
objectCache =
new FileObjectCache(new File(property_directory), ".obj");
} catch (IOException ioe) {
// not possible?
ioe.printStackTrace();
}
webServer.setData(data);
webServer.setProps(props);
webServer.setCache(objectCache);
pt.click("Set web server context objects");
MessageDispatcher.init(this);
ImportManager.init(data);
InternalSettings.addPropertyChangeListener(ImportManager.SETTING_NAME,
EventHandler.create(PropertyChangeListener.class, this,
"flushWorkingData"));
pt.click("Initialized import manager");
data.finishInconsistency();
ExportManager.init(data, this);
pt.click("Initialized export manager");
try {
data.maybeSaveDefinitions(serializedDefinitions);
} catch (Exception e) {
e.printStackTrace();
}
RepairDefectCounts.maybeRun(this, property_directory);
timeLog.refreshMetrics();
pt.click("Refreshed time log metrics");
EVTaskDependencyResolver.init(this);
WBSTaskOrderComparator.init(this);
configure_button = new ConfigureButton(this);
PCSH.enableHelpKey(this, "QuickOverview");
pt.click("Created configure button");
pause_button = new PauseButton(timeLog.getTimeLoggingModel());
pt.click("Created play/pause button");
if (Settings.isPersonalMode())
buildPersonalUI(pt);
else
buildTeamUI(pt);
props.addHierarchyListener(new DashHierarchy.PrePostListener() {
public void hierarchyWillChange(Event e) {
if (!Settings.isFollowMode())
fireApplicationEvent(
ApplicationEventListener.APP_EVENT_SAVE_ALL_DATA);
}
public void hierarchyChanged(Event e) {
saveHierarchy();
registerHierarchyDataElement();
if (!e.isAdjusting() && !Settings.isFollowMode())
timeLog.refreshMetrics();
}});
brokenData.showMissingDataFileWarnings();
TemplateLoader.showTemplateErrors();
ExternalResourceManager.getInstance().cleanupBogusExtResDirectory(
prop_file.getParentFile());
DashController.setDashboard(this);
BackgroundTaskManager.initialize(this);
SystemTrayManagement.getIcon().initialize(this);
AlwaysOnTopManager.initialize(this);
initializeOsHelper();
maybeRecordRecentDataset();
RuntimeUtils.addPropagatedSystemProperty(UsageLogger.FILE_SETTING, null);
RuntimeUtils.autoregisterPropagatedSystemProperties();
if (Settings.isFollowMode())
new FollowModeManager(workingDirectory, props, prop_file,
templates, data, timeLog);
fireApplicationEvent(ApplicationEventListener.APP_EVENT_STARTED);
pt.click("Finished initializing Process Dashboard object");
}