use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.
the class TmfUml2SDSyncLoader method windowRangeUpdated.
/**
* Moves to the page that contains the current time provided by signal. No
* message will be selected however the focus will be set to the message if
* the provided time is the time of a message.
*
* @param signal
* The window range signal
* @since 1.0
*/
@TmfSignalHandler
public void windowRangeUpdated(TmfWindowRangeUpdatedSignal signal) {
fLock.lock();
try {
if ((signal.getSource() != this) && (fFrame != null) && !fIsSignalSent && (!fCheckPoints.isEmpty())) {
TmfTimeRange newTimeRange = signal.getCurrentRange();
fIsSelect = false;
fCurrentTime = newTimeRange.getStartTime();
moveToMessage();
}
} finally {
fLock.unlock();
}
}
use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.
the class TrimTraceHandler method execute.
@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
final TmfCommonProjectElement traceElem = (firstElement instanceof TmfTraceElement) ? ((TmfTraceElement) firstElement).getElementUnderTraceFolder() : (TmfCommonProjectElement) firstElement;
ITmfTrace trace = traceElem.getTrace();
if (trace == null || !isValid(trace)) {
/* That trace is not currently opened */
return null;
}
/* Retrieve the current time range */
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
TmfTraceManager tm = TmfTraceManager.getInstance();
TmfTimeRange timeRange = tm.getTraceContext(trace).getSelectionRange();
if (Objects.equals(timeRange.getStartTime(), timeRange.getEndTime())) {
MessageDialog.openError(shell, Messages.TrimTraces_InvalidTimeRange_DialogTitle, Messages.TrimTraces_InvalidTimeRange_DialogText);
return null;
}
/* Ensure the time range is in the right direction */
final TmfTimeRange tr = ((timeRange.getStartTime().compareTo(timeRange.getEndTime()) > 0) ? new TmfTimeRange(timeRange.getEndTime(), timeRange.getStartTime()) : timeRange);
/*
* Pop a dialog asking the user to select a parent directory for the new
* trace.
*/
TrimTraceDialog dialog = new TrimTraceDialog(shell, traceElem);
if (dialog.open() != Window.OK) {
return null;
}
Object result = dialog.getFirstResult();
if (result == null) {
/* Dialog was cancelled, take no further action. */
return null;
}
/* Verify that the selected path is valid and writeable */
final Path destinationPath = checkNotNull(Paths.get(result.toString()));
if (destinationPath.toFile().exists()) {
MessageDialog.openError(shell, Messages.TrimTraces_InvalidDirectory_DialogTitle, Messages.TrimTraces_InvalidDirectory_DialogText);
return null;
}
TraceToTrim toTrim = TraceToTrim.create(traceElem, destinationPath);
if (toTrim == null) {
return null;
}
try {
toTrim.createDir();
} catch (IOException e) {
/* Should not happen since we have checked permissions, etc. */
throw new ExecutionException(e.getMessage(), e);
}
TmfWorkspaceModifyOperation trimOperation = new TmfWorkspaceModifyOperation() {
@Override
public void execute(@Nullable IProgressMonitor monitor) throws CoreException {
SubMonitor mon = SubMonitor.convert(monitor, 2);
toTrim.trim(tr, mon);
/*
* Import the new trace into the current project, at the
* top-level.
*/
TmfProjectElement currentProjectElement = traceElem.getProject();
TmfTraceFolder traceFolder = currentProjectElement.getTracesFolder();
toTrim.importTrace(mon);
if (mon.isCanceled()) {
return;
}
if (traceFolder != null) {
Display.getDefault().asyncExec(toTrim::open);
} else {
// $NON-NLS-1$
Activator.getDefault().logWarning("Trace folder does not exist: " + toTrim.fDestinationPath);
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().run(true, true, trimOperation);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (InvocationTargetException e) {
TraceUtils.displayErrorMsg(Messages.TrimTraceHandler_failMsg, e.getMessage(), e);
}
return null;
}
use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.
the class TmfUml2SDSyncLoader method findInNextPages.
/**
* Background search in trace for expression in criteria.
*
* @param findCriteria
* The find criteria
* @return true if background request was started else false
*/
protected boolean findInNextPages(Criteria findCriteria) {
fLock.lock();
try {
if (fFindJob != null) {
return true;
}
int nextPage = fCurrentPage + 1;
if ((nextPage) >= fCheckPoints.size()) {
// we are at the end
return false;
}
TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime(), fCheckPoints.get(fCheckPoints.size() - 1).getEndTime());
fFindJob = new SearchJob(findCriteria, window);
fFindJob.schedule();
fView.toggleWaitCursorAsync(true);
} finally {
fLock.unlock();
}
return true;
}
use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.
the class TmfUml2SDSyncLoader method loadTrace.
/**
* Method for loading the current selected trace into the view. Sub-class
* need to override this method to add the view specific implementation.
*/
protected void loadTrace() {
ITmfEventRequest indexRequest = null;
fLock.lock();
try {
// $NON-NLS-1$ //$NON-NLS-2$
final Job job = new IndexingJob("Indexing " + getName() + "...");
job.setUser(false);
job.schedule();
indexRequest = fIndexRequest;
cancelOngoingRequests();
TmfTimeRange window = TmfTimeRange.ETERNITY;
fIndexRequest = new TmfEventRequest(ITmfEvent.class, window, 0, ITmfEventRequest.ALL_DATA, ITmfEventRequest.ExecutionType.BACKGROUND) {
private ITmfTimestamp fFirstTime = null;
private ITmfTimestamp fLastTime = null;
private int fNbSeqEvents = 0;
private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<>(MAX_NUM_OF_MSG);
@Override
public void handleData(ITmfEvent event) {
super.handleData(event);
ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
ITmfTimestamp firstTime = fFirstTime;
ITmfTimestamp lastTime = fLastTime;
if (sdEvent != null) {
++fNbSeqEvents;
if (firstTime == null) {
firstTime = event.getTimestamp();
fFirstTime = firstTime;
}
lastTime = event.getTimestamp();
fLastTime = lastTime;
if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
fLock.lock();
try {
fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
if (fView != null) {
fView.updateCoolBar();
}
} finally {
fLock.unlock();
}
fFirstTime = null;
}
if (fNbSeqEvents > MAX_NUM_OF_MSG) {
// page is full
return;
}
fSdEvents.add(sdEvent);
if (fNbSeqEvents == MAX_NUM_OF_MSG) {
fillCurrentPage(fSdEvents);
}
}
}
@Override
public void handleSuccess() {
final ITmfTimestamp firstTime = fFirstTime;
final ITmfTimestamp lastTime = fLastTime;
if ((firstTime != null) && (lastTime != null)) {
fLock.lock();
try {
fCheckPoints.add(new TmfTimeRange(firstTime, lastTime));
if (fView != null) {
fView.updateCoolBar();
}
} finally {
fLock.unlock();
}
}
if (fNbSeqEvents <= MAX_NUM_OF_MSG) {
fillCurrentPage(fSdEvents);
}
super.handleSuccess();
}
@Override
public void handleCompleted() {
if (fEvents.isEmpty()) {
fFrame = new Frame();
// make sure that view is not null when setting frame
SDView sdView;
fLock.lock();
try {
sdView = fView;
} finally {
fLock.unlock();
}
if (sdView != null) {
sdView.setFrameSync(fFrame);
}
}
super.handleCompleted();
job.cancel();
}
};
} finally {
fLock.unlock();
}
if (indexRequest != null && !indexRequest.isCompleted()) {
indexRequest.cancel();
}
resetLoader();
fTrace.sendRequest(fIndexRequest);
}
use of org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange in project tracecompass by tracecompass.
the class HistogramCurrentTimeControl method updateValue.
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
protected void updateValue() {
if (getValue() == Long.MIN_VALUE) {
// $NON-NLS-1$
fTextValue.setText("");
return;
}
String string = fTextValue.getText();
long value = getValue();
try {
value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
} catch (ParseException e) {
}
if (getValue() != value) {
// Make sure that the new time is within range
ITmfTrace trace = fParentView.getTrace();
if (trace != null) {
TmfTimeRange range = trace.getTimeRange();
long startTime = range.getStartTime().toNanos();
long endTime = range.getEndTime().toNanos();
if (value < startTime) {
value = startTime;
} else if (value > endTime) {
value = endTime;
}
}
// Set and propagate
setValue(value);
updateSelectionTime(value);
} else {
setValue(value);
}
}
Aggregations