use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class LogSearchResultPage method showMatch.
@Override
protected void showMatch(final Match match, final int currentOffset, final int currentLength, final boolean activate) throws PartInitException {
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
if (!selection.toList().contains(match)) {
treeViewer.setSelection(new StructuredSelection(match));
}
IFile logFile = (IFile) match.getElement();
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
TextTableView openedView;
IViewReference viewReference = activePage.findViewReference(Constants.TEXT_TABLE_VIEW_ID, logFile.getFullPath().toOSString());
if (viewReference == null) {
openTextTableView(logFile, match.getOffset());
return;
}
TextTableView view = (TextTableView) viewReference.getView(false);
if (view != null && view.isFiltered() && !view.contains(match.getOffset())) {
MessageBox mb = new MessageBox(this.getSite().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
mb.setText("Filtered match");
mb.setMessage("The selected record can not be displayed in the opened TextTableView." + " Would you like to open a new view? (The old one will be closed)");
switch(mb.open()) {
case SWT.YES:
activePage.hideView(viewReference);
openTextTableView(logFile, match.getOffset());
break;
case SWT.NO:
break;
default:
return;
}
return;
}
openedView = (TextTableView) activePage.showView(Constants.TEXT_TABLE_VIEW_ID, logFile.getFullPath().toOSString(), org.eclipse.ui.IWorkbenchPage.VIEW_VISIBLE);
openedView.setSelectedRecord(match.getOffset());
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class MSCView method createPartControl.
@Override
public void createPartControl(final Composite c) {
// restores any saved state
final WorkspaceJob job = restoreState();
if (this.problemDuringRestore) {
Label text = new Label(c, SWT.LEFT);
// $NON-NLS-1$
text.setText(Messages.getString("MSCView.0"));
return;
}
Composite parent = new Composite(c, SWT.NONE);
GridLayout parentLayout = new GridLayout();
parentLayout.numColumns = 1;
parentLayout.marginWidth = 0;
parentLayout.marginHeight = 0;
parent.setLayout(parentLayout);
GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
this.mscWidget = new MSCWidget(parent, SWT.NONE);
this.mscWidget.setLayoutData(seqDiagLayoutData);
this.mscWidget.setDragAutoScroll(false);
this.mscWidget.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(final KeyEvent e) {
if (e.keyCode != SWT.CR) {
return;
}
PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(MSCView.this.logFileMetaData.getProjectName());
int defaultBehaviour = preferences.getMscViewDefault();
if (defaultBehaviour == PreferenceConstants.DEFAULT_TEXT) {
MSCView.this.openTextTable.run();
} else {
MSCView.this.openValueView.run();
}
}
});
this.mscWidget.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(final MouseEvent e) {
PreferencesHolder preferences = PreferencesHandler.getInstance().getPreferences(MSCView.this.logFileMetaData.getProjectName());
int defaultBehaviour = preferences.getMscViewDefault();
if (defaultBehaviour == PreferenceConstants.DEFAULT_TEXT) {
MSCView.this.openTextTable.run();
} else {
MSCView.this.openValueView.run();
}
}
});
this.mscWidget.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
if (!(event.getSelection() instanceof IStructuredSelection)) {
return;
}
if (MSCView.this.model == null) {
return;
}
final IFile logFile = MSCView.this.model.getTestCase().getLogFile();
if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
LogFileCacheHandler.handleLogFileChange(logFile);
return;
}
final IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection();
final IViewReference[] viewReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
if (MSCView.this.logFileMetaData == null) {
return;
}
for (IViewReference viewReference : viewReferences) {
final IViewPart viewPart = viewReference.getView(false);
if (viewPart instanceof TextTableView && ((TextTableView) viewPart).getLogFileMetaData() != null && MSCView.this.logFileMetaData.getFilePath().equals(((TextTableView) viewPart).getLogFileMetaData().getFilePath())) {
final Integer selectedLine = (Integer) structuredSelection.getFirstElement();
final int recordNumber = MSCView.this.model.getEvent(selectedLine - 2).getRecordNumber();
TextTableView textTableView = (TextTableView) viewPart;
if (textTableView.getSelectedRecord() != null && textTableView.getSelectedRecord().getRecordNumber() != recordNumber) {
textTableView.setSelectedRecord(recordNumber);
}
break;
}
}
silentOpenSource.delayedRun(event.getSelection());
silentOpenValueView.delayedRun(event.getSelection());
}
});
createCoolbarContent();
hookContextMenu();
parent.layout(true);
WorkspaceJob job2 = new WorkspaceJob("Displaying loaded log information") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
if (job == null) {
return Status.OK_STATUS;
}
try {
job.join();
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
// Check if model was restored
if ((MSCView.this.logFileMetaData != null) && (MSCView.this.model != null)) {
// always open restore at top
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
setModel(MSCView.this.model, MSCView.this.restoredSelection);
}
});
}
return Status.OK_STATUS;
}
};
job2.setSystem(true);
job2.schedule();
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class MSCView method createCoolbarContent.
/**
* Creates the coolBar icon depending on the actions supported by the
* Message Sequence Chart provider<br>
* - Navigation buttons are displayed if ISDPovider.HasPaging return true<br>
* - Navigation buttons are enabled depending on the value
* return by ISDPovider.HasNext and HasPrev<br>
*/
protected void createCoolbarContent() {
IActionBars bar = getViewSite().getActionBars();
bar.getToolBarManager().removeAll();
createMenuGroups();
this.openValueView = new OpenValueViewAction(this, true);
this.openValueView.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_DETAILS_VIEW));
this.silentOpenValueView = new OpenValueViewAction(this, false);
this.silentOpenValueView.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_DETAILS_VIEW));
this.openTextTable = new OpenTextTableAction(this);
this.openTextTable.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));
this.openSource = new OpenSourceAction(this, false, true);
this.openSource.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));
this.silentOpenSource = new OpenSourceAction(this, true, false);
this.silentOpenSource.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));
IAction switchToTextTable = new Action() {
@Override
public void run() {
if (logFileMetaData == null) {
return;
}
TextTableViewHelper.open(logFileMetaData.getProjectName(), logFileMetaData.getProjectRelativePath(), getSelectedRecordNumber());
}
};
switchToTextTable.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(Constants.ICONS_TEXT_TABLE_VIEW));
switchToTextTable.setText("Switch to Table view");
switchToTextTable.setToolTipText(switchToTextTable.getText());
bar.getToolBarManager().appendToGroup(Constants.ID_SWITCH_VIEW_GROUP, switchToTextTable);
this.jumpToPreviousSetverdict = new JumpToPreviousSetverdictAction(this);
// $NON-NLS-1$
this.jumpToPreviousSetverdict.setId("jumpToNextSetVerdict");
// $NON-NLS-1$
this.jumpToPreviousSetverdict.setText(Messages.getString("MSCView.11"));
// $NON-NLS-1$
this.jumpToPreviousSetverdict.setToolTipText(Messages.getString("MSCView.12"));
this.jumpToPreviousSetverdict.setImageDescriptor(ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_JUMP_TO_PREVIOUS)));
this.jumpToPreviousSetverdict.setEnabled(false);
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, this.jumpToPreviousSetverdict);
this.jumpToNextSetverdict = new JumpToNextSetverdictAction(this);
// $NON-NLS-1$
this.jumpToNextSetverdict.setId("jumpToNextSetVerdict");
// $NON-NLS-1$
this.jumpToNextSetverdict.setText(Messages.getString("MSCView.13"));
// $NON-NLS-1$
this.jumpToNextSetverdict.setToolTipText(Messages.getString("MSCView.14"));
this.jumpToNextSetverdict.setImageDescriptor(ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_JUMP_TO_NEXT)));
this.jumpToNextSetverdict.setEnabled(false);
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, this.jumpToNextSetverdict);
this.refresh = new RefreshMSCViewAction(this);
// $NON-NLS-1$
this.refresh.setId("refreshMSCView");
// $NON-NLS-1$
this.refresh.setToolTipText(Messages.getString("MSCView.1"));
this.refresh.setImageDescriptor(ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_REFRESH)));
IActionBars actionBar = getViewSite().getActionBars();
actionBar.setGlobalActionHandler(ActionFactory.REFRESH.getId(), this.refresh);
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, this.refresh);
IAction closeAllAction = new Action() {
@Override
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference[] viewReferences = activePage.getViewReferences();
for (IViewReference reference : viewReferences) {
IViewPart view = reference.getView(false);
// memento restored views that never have had focus are null!!!
if (view == null) {
activePage.hideView(reference);
} else if (view instanceof MSCView) {
activePage.hideView(reference);
}
}
// Clear Details view if needed
DetailsView detailsView = (DetailsView) activePage.findView(Constants.DETAILS_VIEW_ID);
if (detailsView != null) {
detailsView.setData(null, false);
}
}
};
closeAllAction.setImageDescriptor(ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_DELETE)));
// $NON-NLS-1$
closeAllAction.setId("closeMSC");
// $NON-NLS-1$
closeAllAction.setToolTipText(Messages.getString("MSCView.2"));
closeAllAction.setEnabled(true);
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, closeAllAction);
ZoomAction resetZoom = new ZoomAction(this);
resetZoom.setId(MSCConstants.ID_RESET_ZOOM);
// $NON-NLS-1$
resetZoom.setText(Messages.getString("MSCView.3"));
// $NON-NLS-1$
resetZoom.setToolTipText(Messages.getString("MSCView.4"));
resetZoom.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_RESET_ZOOM));
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, resetZoom);
ZoomAction noZoom = new ZoomAction(this);
noZoom.setChecked(true);
noZoom.setId(MSCConstants.ID_NO_ZOOM);
// $NON-NLS-1$
noZoom.setText(Messages.getString("MSCView.5"));
// $NON-NLS-1$
noZoom.setToolTipText(Messages.getString("MSCView.6"));
noZoom.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_MOVE));
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, noZoom);
ZoomAction zoomIn = new ZoomAction(this);
zoomIn.setId(MSCConstants.ID_ZOOM_IN);
// $NON-NLS-1$
zoomIn.setText(Messages.getString("MSCView.7"));
// $NON-NLS-1$
zoomIn.setToolTipText(Messages.getString("MSCView.8"));
zoomIn.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_ZOOM_IN));
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, zoomIn);
ZoomAction zoomOut = new ZoomAction(this);
zoomOut.setId(MSCConstants.ID_ZOOM_OUT);
// $NON-NLS-1$
zoomOut.setText(Messages.getString("MSCView.9"));
// $NON-NLS-1$
zoomOut.setToolTipText(Messages.getString("MSCView.10"));
zoomOut.setImageDescriptor(Activator.getDefault().getCachedImageDescriptor(MSCConstants.ICON_ZOOM_OUT));
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, zoomOut);
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, filterAction);
Action decipheringAction = new Action() {
@Override
public void run() {
final List<String> rulesets = DecipheringPreferenceHandler.getAvailableRuleSets();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(MSCView.this.getSite().getShell(), new LabelProvider());
dialog.setTitle("Message name deciphering");
dialog.setMessage("Select a deciphering ruleset");
dialog.setHelpAvailable(false);
dialog.setElements(rulesets.toArray());
if (dialog.open() == Window.CANCEL || dialog.getFirstResult() == null) {
return;
}
MSCView.this.model.setDecipheringRuleset((String) dialog.getFirstResult());
mscWidget.redraw();
}
};
decipheringAction.setImageDescriptor(Activator.getImageDescriptor(Constants.ICONS_MSC_DECIPHERING));
decipheringAction.setToolTipText("Select a message name deciphering ruleset");
bar.getToolBarManager().appendToGroup(MSCConstants.ID_ZOOM_GROUP, decipheringAction);
bar.updateActionBars();
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class StatisticalView method createToolbar.
/**
* Create a close all action in the tool bar
*/
private void createToolbar() {
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager mgr = actionBars.getToolBarManager();
IAction closeAllAction = new Action() {
@Override
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference[] viewReferences = activePage.getViewReferences();
for (IViewReference reference : viewReferences) {
IViewPart view = reference.getView(false);
// null!!!
if (view == null) {
activePage.hideView(reference);
} else if (view instanceof StatisticalView) {
activePage.hideView(reference);
}
}
}
};
closeAllAction.setImageDescriptor(ImageDescriptor.createFromImage(Activator.getDefault().getIcon(Constants.ICONS_MSC_DELETE)));
// $NON-NLS-1$
closeAllAction.setId(Messages.getString("StatisticalView.27"));
// $NON-NLS-1$
closeAllAction.setToolTipText(Messages.getString("StatisticalView.26"));
closeAllAction.setEnabled(true);
mgr.add(closeAllAction);
actionBars.updateActionBars();
}
use of org.eclipse.ui.IViewReference in project titan.EclipsePlug-ins by eclipse.
the class TextTableViewHelper method open.
/**
* Opens a TextTable view for the given log file. If the view is already open
* the record with the number recordToSelect will be selected.
* @param projectName The name of the logfile's project.
* @param projectRelativePath The project relative path of the log file
* @param recordToSelect The number of the record that will be initially selected.
* @return The newly created view or null if the view can not be opened.
*/
public static TextTableView open(final String projectName, final String projectRelativePath, final int recordToSelect) {
String secondId = projectRelativePath;
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference reference = activePage.findViewReference(Constants.TEXT_TABLE_VIEW_ID, secondId);
if (reference != null) {
try {
TextTableView view = (TextTableView) activePage.showView(Constants.TEXT_TABLE_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
view.setSelectedRecord(recordToSelect);
view.setFocus();
return view;
} catch (PartInitException e) {
// do nothing
}
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject(projectName);
final IFile logFile = project.getFile(projectRelativePath.substring(projectName.length() + 1));
if (!logFile.exists()) {
IViewReference[] viewReferences = activePage.getViewReferences();
ActionUtils.closeAssociatedViews(activePage, viewReferences, logFile);
// $NON-NLS-1$
TitanLogExceptionHandler.handleException(new UserException(Messages.getString("OpenMSCViewMenuAction.4")));
return null;
}
try {
Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
if (temp != null && (Boolean) temp) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openInformation(null, "View can not be opened.", "Test case extraction is already running on " + logFile.getName());
}
});
return null;
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
}
if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
LogFileCacheHandler.handleLogFileChange(logFile);
return null;
}
try {
TextTableView view = (TextTableView) activePage.showView(Constants.TEXT_TABLE_VIEW_ID, secondId, IWorkbenchPage.VIEW_ACTIVATE);
view.setInput(logFile, recordToSelect);
view.setFocus();
return view;
} catch (FileNotFoundException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.0") + e.getMessage()));
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.1") + e.getMessage()));
} catch (PartInitException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.2") + e.getMessage()));
} catch (ClassNotFoundException e) {
ErrorReporter.logExceptionStackTrace(e);
TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("OpenTextTableTestCasesViewMenuAction.2") + e.getMessage()));
}
return null;
}
Aggregations