use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class OpenMSCViewMenuAction method run.
public void run(final IStructuredSelection selection) {
if (!isEnabled()) {
return;
}
Object element = selection.getFirstElement();
if (!(element instanceof TestCase)) {
return;
}
final TestCase tc = (TestCase) element;
final IFile logFile = tc.getLogFile();
try {
logFileMetaData = LogFileCacheHandler.logFileMetaDataReader(LogFileCacheHandler.getPropertyFileForLogFile(logFile));
} catch (IOException e1) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
} catch (ClassNotFoundException e1) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
}
try {
if (!PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName()).getVisualOrderComponents().isEmpty()) {
// Get start time
final long start = new Date().getTime();
if (!logFile.exists()) {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference[] viewReferences = activePage.getViewReferences();
ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenMSCViewMenuAction.4")));
return;
}
// Check if the file has been modified
if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
}
// Get log record index file for selected log file - No need to check is exists due to
// LogFileCacheHandler.hasLogFileChanged(logFile) returning false above
File logRecordIndexFile = LogFileCacheHandler.getLogRecordIndexFileForLogFile(logFile);
final LogRecordIndex[] logRecordIndexes = LogFileCacheHandler.readLogRecordIndexFile(logRecordIndexFile, tc.getStartRecordNumber(), tc.getNumberOfRecords());
final PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(this.logFileMetaData.getProjectName());
WorkspaceJob job = new WorkspaceJob("Loading log information") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
if (OpenMSCViewMenuAction.this.logFileMetaData == null || OpenMSCViewMenuAction.this.logFileMetaData.getExecutionMode() == null) {
return Status.CANCEL_STATUS;
}
final Parser parser;
final ExecutionModel model;
try {
parser = new Parser(OpenMSCViewMenuAction.this.logFileMetaData);
parser.setStart(start);
model = parser.preParse(tc, logRecordIndexes, preferences, null, monitor);
} catch (TechnicalException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
Messages.getString("OpenMSCViewMenuAction.3") + e.getMessage()));
return Status.CANCEL_STATUS;
} catch (ParseException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(// $NON-NLS-1$
Messages.getString("OpenMSCViewMenuAction.2") + e.getMessage()));
return Status.CANCEL_STATUS;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
return Status.CANCEL_STATUS;
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
showView(model, parser, tc);
// Write data to the console
final long end = new Date().getTime();
parser.setEnd(end);
ConsoleWriter.getInstance().writeModelData(OpenMSCViewMenuAction.this.logFileMetaData.getProjectName(), parser, model, OpenMSCViewMenuAction.this.logFileMetaData.getFilePath().toString());
}
});
return Status.OK_STATUS;
}
};
job.schedule();
} else {
// $NON-NLS-1$
String userE = Messages.getString("OpenMSCViewMenuAction.1");
TitanLogExceptionHandler.handleException(new UserException(userE));
}
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while parsing of the log file", e);
TitanLogExceptionHandler.handleException(new TechnicalException(e.getMessage()));
}
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class OpenStatisticalViewMenuAction method run.
public void run(final IStructuredSelection selection) {
this.logFileMetaData = null;
this.logFileIsSupported = true;
if (this.selection == null) {
return;
}
Set<IFile> logFiles = new HashSet<IFile>(selection.size());
for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
if (object instanceof IFile) {
logFiles.add((IFile) object);
} else if (object instanceof TestCase) {
logFiles.add(((TestCase) object).getLogFile());
}
}
if (logFiles.isEmpty()) {
return;
}
List<StatisticalData> statisticalDataVector = createStatisticalData(logFiles);
if (statisticalDataVector == null || statisticalDataVector.isEmpty()) {
return;
}
String secondId = Constants.STATISTICAL_VIEW;
if (statisticalDataVector.size() < 2) {
secondId = File.separator + this.logFile.getProject().getName() + File.separator + this.logFile.getProjectRelativePath().toOSString();
}
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference reference = activePage.findViewReference(Constants.STATISTICAL_VIEW_ID, secondId);
// get the view
if (reference != null) {
StatisticalView part = (StatisticalView) reference.getView(false);
}
// create a new view
try {
StatisticalView part = (StatisticalView) activePage.showView(Constants.STATISTICAL_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
part.setData(statisticalDataVector);
part.setFocus();
} catch (PartInitException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenStatisticalViewMenuAction.0") + e.getMessage()));
}
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class TextTableViewHelper method updateSelectionInConnectedMscView.
static void updateSelectionInConnectedMscView(int selectedRecord, LogFileMetaData fileMetaData) {
final IViewReference[] viewReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
for (IViewReference viewReference : viewReferences) {
final IViewPart viewPart = viewReference.getView(false);
if (!(viewPart instanceof MSCView)) {
continue;
}
final MSCView mscView = (MSCView) viewPart;
if (mscView.getModel() == null || mscView.getModel().getTestCase() == null) {
continue;
}
final TestCase testCase = mscView.getModel().getTestCase();
if (fileMetaData.getFilePath().equals((mscView).getLogFileMetaData().getFilePath()) && testCase.getStartRecordNumber() <= selectedRecord && testCase.getEndRecordNumber() >= selectedRecord) {
if (mscView.getSelectedRecordNumber() != selectedRecord) {
mscView.setSelection(selectedRecord);
}
// Only one MSC view can be opened for one test case
break;
}
}
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class ActionUtils method closeViewsForProject.
/**
* Closes all connected views when closing/deleting a project
* and clear the test case tabbed navigator if necessary
* @param project the selected project
* @param activePage activePage page
* @param viewReferences views
*/
private static void closeViewsForProject(final IProject project, final IWorkbenchPage activePage, final IViewReference[] viewReferences) {
for (IViewReference reference : viewReferences) {
IViewPart view = reference.getView(false);
closeView(project, activePage, reference, view);
}
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class LogFileCacheHandler method handleLogFileChange.
/**
* Should be called when a log file has changed. Closes the associated views. Shows a <code>MessageBox</code> where the user can decide if he/she wants to process
* the log file or just close the views. If the user choose yes, the processing will start in a new <code>WorkspaceJob</code>.
* @param logFile
*/
public static void handleLogFileChange(final IFile logFile) {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IViewReference[] viewReferences = activePage.getViewReferences();
ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
clearCache(logFile);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
if (view instanceof CommonNavigator) {
CommonNavigator navigator = (CommonNavigator) view;
navigator.getCommonViewer().collapseToLevel(logFile, AbstractTreeViewer.ALL_LEVELS);
}
}
});
MessageBox mb = new MessageBox(activePage.getActivePart().getSite().getShell(), SWT.ICON_ERROR | SWT.OK | SWT.CANCEL);
mb.setText("The log file has been modified.");
mb.setMessage("The log file has been modified. Click on OK to extract the test cases" + " or CANCEL to close the associated views.");
if (mb.open() == SWT.OK) {
WorkspaceJob job = new WorkspaceJob("Testcase extraction from log file: " + logFile.getName()) {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
boolean completed = LogFileCacheHandler.processLogFile(logFile, monitor, false);
return completed ? Status.OK_STATUS : Status.CANCEL_STATUS;
}
};
job.setPriority(Job.LONG);
job.setUser(true);
job.setRule(logFile.getProject());
job.schedule();
}
}
Aggregations