use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class RcpCliParser method workspaceLoading.
@Override
public IStatus workspaceLoading(CliCommandLine commandLine, IProgressMonitor monitor) {
if (commandLine.hasOption(OPTION_COMMAND_LINE_OPEN_SHORT)) {
IProject defaultProject = createDefaultProject();
IStatus returnStatus = Status.OK_STATUS;
List<Path> allTracePaths = replaceHomeDir(commandLine.getOptionValues(OPTION_COMMAND_LINE_OPEN_SHORT));
List<Path> tracePaths = new ArrayList<>();
// Remove paths that do not exist
for (Path tracePath : allTracePaths) {
if (!tracePath.toFile().exists()) {
returnStatus = addStatus(returnStatus, new Status(IStatus.ERROR, TracingRcpPlugin.PLUGIN_ID, NLS.bind(Messages.CliParser_TraceDoesNotExist, tracePath)));
} else {
tracePaths.add(tracePath);
}
}
Collection<TmfCommonProjectElement> existingTraceElement = findElements(tracePaths);
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
WaitAllTracesOpened service = openTraceIfNecessary(defaultProject, tracePaths, existingTraceElement, monitor);
returnStatus = addStatus(returnStatus, service.waitForCompletion(monitor));
service.dispose();
return returnStatus;
}
return Status.OK_STATUS;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class SelectTraceTypeHandler method execute.
// ------------------------------------------------------------------------
// Execution
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Check if we are closing down
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return null;
}
List<IStatus> statuses = new ArrayList<>();
Set<TmfProjectElement> projects = new HashSet<>();
boolean ok = true;
for (Object element : fSelection.toList()) {
TmfCommonProjectElement trace = (TmfCommonProjectElement) element;
if (trace instanceof TmfTraceElement) {
trace = ((TmfTraceElement) trace).getElementUnderTraceFolder();
}
IResource resource = trace.getResource();
if (resource != null) {
try {
// Set the trace type for this resource
String traceType = event.getParameter(TYPE_PARAMETER);
String previousTraceType = trace.getTraceType();
IStatus status = propagateProperties(trace, traceType);
ok &= status.isOK();
if (status.isOK()) {
if ((previousTraceType != null) && (!traceType.equals(previousTraceType))) {
// Close the trace if open
trace.closeEditors();
// Delete all supplementary resources
trace.deleteSupplementaryResources();
}
} else {
statuses.add(status);
}
projects.add(trace.getProject());
} catch (CoreException e) {
Activator.getDefault().logError(Messages.SelectTraceTypeHandler_ErrorSelectingTrace + trace.getName(), e);
}
}
trace.getProject();
}
for (TmfProjectElement project : projects) {
project.refresh();
}
if (!ok) {
final Shell shell = window.getShell();
MultiStatus info = new MultiStatus(Activator.PLUGIN_ID, 1, Messages.SelectTraceTypeHandler_TraceFailedValidation, null);
if (statuses.size() > 1) {
info = new MultiStatus(Activator.PLUGIN_ID, 1, Messages.SelectTraceTypeHandler_TracesFailedValidation, null);
}
for (IStatus status : statuses) {
info.add(status);
}
ErrorDialog.openError(shell, Messages.SelectTraceTypeHandler_Title, Messages.SelectTraceTypeHandler_InvalidTraceType, info);
}
return null;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TrimTraceHandler method isEnabled.
@Override
public boolean isEnabled() {
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null) {
return false;
}
@SuppressWarnings("null") IHandlerService service = workbench.getService(IHandlerService.class);
// we need the current state, and the map, but the command and the
// trigger are
// not necessary for getCurrentSelection
ExecutionEvent executionEvent = new ExecutionEvent(null, Collections.emptyMap(), null, service.getCurrentState());
final Object element = HandlerUtil.getCurrentSelection(executionEvent);
if (!(element instanceof TreeSelection)) {
return false;
}
/*
* plugin.xml should have done type/count verification already
*/
Object firstElement = ((TreeSelection) element).getFirstElement();
ITmfTrace trace = null;
if (firstElement instanceof TmfCommonProjectElement) {
TmfCommonProjectElement traceElem = (TmfCommonProjectElement) firstElement;
if (traceElem instanceof TmfTraceElement) {
traceElem = ((TmfTraceElement) traceElem).getElementUnderTraceFolder();
}
trace = traceElem.getTrace();
}
if (trace == null || !isValid(trace)) {
return false;
}
/* Only enable the action if a time range is currently selected */
TmfTraceManager tm = TmfTraceManager.getInstance();
TmfTimeRange selectionRange = tm.getTraceContext(trace).getSelectionRange();
return !(selectionRange.getStartTime().equals(selectionRange.getEndTime()));
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class RunAnalysisHandler method execute.
@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
/* Types should have been checked by the plugin.xml already */
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
Object element = ((IStructuredSelection) selection).getFirstElement();
final TmfOnDemandAnalysisElement analysisElem = (TmfOnDemandAnalysisElement) element;
TmfCommonProjectElement traceElem = analysisElem.getParent().getParent();
ITmfTrace trace = traceElem.getTrace();
if (trace == null) {
/* That trace is not currently opened */
return null;
}
/* Retrieve and initialize the analysis module, aka read the script's metadata */
IOnDemandAnalysis ondemandAnalysis = analysisElem.getAnalysis();
if (!(ondemandAnalysis instanceof LamiAnalysis)) {
return null;
}
LamiAnalysis analysis = (LamiAnalysis) ondemandAnalysis;
/* Retrieve the current time range, will be used as parameters to the analysis */
TmfTraceManager tm = TmfTraceManager.getInstance();
TmfTimeRange timeRange = tm.getCurrentTraceContext().getSelectionRange();
if (timeRange.getStartTime().equals(timeRange.getEndTime())) {
timeRange = null;
}
/* Job below needs a final reference... */
final TmfTimeRange tr = timeRange;
/* Pop the dialog to ask for extra parameters */
String baseCommand = analysis.getFullCommandAsString(trace, tr);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
ParameterDialog dialog = new ParameterDialog(shell, Messages.ParameterDialog_ExternalParameters, Messages.ParameterDialog_ExternalParametersDescription, baseCommand, null);
if (dialog.open() != Window.OK) {
/* User clicked Cancel, don't run */
return null;
}
String extraParams = nullToEmptyString(dialog.getValue());
/* Execute the analysis and produce the reports */
Job job = new Job(Messages.LamiAnalysis_MainTaskName) {
@Override
@Nullable
protected IStatus run(@Nullable IProgressMonitor monitor) {
IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
try {
List<LamiResultTable> results = analysis.execute(trace, tr, extraParams, mon);
String reportName = analysis.getName() + ' ' + Messages.ParameterDialog_ReportNameSuffix;
LamiAnalysisReport report = new LamiAnalysisReport(reportName, results);
registerNewReport(analysisElem, report);
/* Automatically open the report for convenience */
Display.getDefault().syncExec(() -> {
try {
LamiReportViewFactory.createNewView(report);
} catch (PartInitException e) {
}
});
return Status.OK_STATUS;
} catch (CoreException e) {
/*
* The analysis execution did not complete normally, we will
* report it to the user.
*/
IStatus status = e.getStatus();
/* Don't display a dialog if it was simply cancelled by the user */
if (status.matches(IStatus.CANCEL)) {
return status;
}
String dialogTitle;
String dialogMessage;
if (status.matches(IStatus.ERROR)) {
dialogTitle = Messages.ErrorDialog_Error;
dialogMessage = Messages.ErrorDialog_ErrorMessage;
} else {
dialogTitle = Messages.ErrorDialog_Info;
dialogMessage = Messages.ErrorDialog_InfoMessage;
}
Display.getDefault().asyncExec(() -> {
ErrorDialog.openError(shell, dialogTitle, dialogMessage, status);
});
/*
* We showed our own error message, no need for the Job to
* show another one.
*/
return Status.OK_STATUS;
}
}
};
job.schedule();
return null;
}
Aggregations