package com.onaro.sanscreen.client.view.migration; import java.text.DateFormat; import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.ResourceBundle; import org.eclipse.core.runtime.IAdaptable; import com.onaro.client.DateFormats; import com.onaro.sanscreen.client.SessionsHelper; import com.onaro.sanscreen.client.error.CentralErrorHandler; import com.onaro.sanscreen.client.view.GroupingDirector; import com.onaro.sanscreen.client.view.selection.SelectedObject; import com.onaro.sanscreen.client.view.selection.SelectedObjectUtils; import com.onaro.sanscreen.client.view.tabular.GroupingSubTitleGenerator; import com.onaro.sanscreen.server.migration.query.data.MigrationTask; import com.onaro.sanscreen.server.migration.sessions.MigrationException; import com.onaro.sanscreen.util.Constant; /** * Generates sub title string to be added in the grouping director toolbar * The sub title shows the migration start time (the time that the QA micro view compares the violations with) */ public class MigrationTaskSubTitleGenerator implements GroupingSubTitleGenerator { private final DateFormat dateTimeFormat = DateFormats.getShortDateTimeFormat(); private String messageFormat; public MigrationTaskSubTitleGenerator() { ResourceBundle resources = ResourceBundle.getBundle("com.onaro.sanscreen.client.view.migration.switchMigration"); //$NON-NLS-1$ messageFormat = resources.getString("switch.migration.qa.sub.title"); //$NON-NLS-1$ } /** * Generates sub title string to be added in the grouping director toolbar * * @param groupingDirector contains the selected task id * @return the migration start time (the time that the QA micro view compares the violations with) as a sub title text */ public String generateSubTitle(GroupingDirector groupingDirector) { List selectedContexts = groupingDirector.getShowingAdaptables(); SelectedObject selectedObject = SelectedObjectUtils.getFirstSelectedObject(selectedContexts); if (selectedObject != null) { try { long taskId = selectedObject.getObjId(); MigrationTask task = SessionsHelper.getInstance().getMigrationSession().getMigrationTask(taskId); if (task != null) { long migrationStartTime = task.getSnapshotTime(); if (migrationStartTime > 0 && migrationStartTime != Constant.END_DATE) { String dateString = dateTimeFormat.format(new Date(migrationStartTime)); return MessageFormat.format(messageFormat, dateString); } } } catch (MigrationException e) { CentralErrorHandler.handle("Failed to fetch migration start time of task '" + selectedObject.getName() + "'", e); //$NON-NLS-1$ //$NON-NLS-2$ } catch (SessionsHelper.SessionsException e) { CentralErrorHandler.handle("Failed to fetch migration start time of task '" + selectedObject.getName() + "'", e); //$NON-NLS-1$ //$NON-NLS-2$ } } return null; } }