use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class TracePackageExportOperation method run.
/**
* Run the operation. The status (result) of the operation can be obtained
* with {@link #getStatus}
*
* @param progressMonitor
* the progress monitor to use to display progress and receive
* requests for cancellation
*/
@Override
public void run(IProgressMonitor progressMonitor) {
try {
int totalWork = getNbCheckedElements(fTraceExportElements) * 2;
progressMonitor.beginTask(Messages.TracePackageExportOperation_GeneratingPackage, totalWork);
fExportFolder = createExportFolder(progressMonitor);
Document doc = XmlUtils.newSafeDocumentBuilderFactory().newDocumentBuilder().newDocument();
Element createElement = doc.createElement(ITracePackageConstants.TMF_EXPORT_ELEMENT);
Node tmfNode = doc.appendChild(createElement);
List<TracePackageExperimentElement> experimentPackageElements = new ArrayList<>();
for (TracePackageTraceElement tracePackageElement : fTraceExportElements) {
if (!isFilesChecked(tracePackageElement)) {
continue;
}
if (tracePackageElement instanceof TracePackageExperimentElement) {
experimentPackageElements.add((TracePackageExperimentElement) tracePackageElement);
} else {
exportTrace(progressMonitor, tmfNode, tracePackageElement);
}
}
for (TracePackageExperimentElement experimentPackageElement : experimentPackageElements) {
exportExperiment(progressMonitor, tmfNode, experimentPackageElement);
}
Transformer transformer = XmlUtils.newSecureTransformer();
// $NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// $NON-NLS-1$ //$NON-NLS-2$
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(doc);
StringWriter buffer = new StringWriter();
StreamResult result = new StreamResult(buffer);
transformer.transform(source, result);
String content = buffer.getBuffer().toString();
ModalContext.checkCanceled(progressMonitor);
exportManifest(content);
setStatus(exportToArchive(progressMonitor, totalWork));
fExportFolder.delete(true, SubMonitor.convert(progressMonitor));
progressMonitor.done();
} catch (InterruptedException e) {
setStatus(Status.CANCEL_STATUS);
Thread.currentThread().interrupt();
} catch (Exception e) {
setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e));
}
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class TracePackageExportOperation method exportCommon.
private Node exportCommon(IProgressMonitor monitor, Node tmfNode, TracePackageTraceElement tracePackageElement, String elementString) throws InterruptedException, CoreException {
TmfCommonProjectElement commonElement = tracePackageElement.getTraceElement();
Element commonXmlElement = tmfNode.getOwnerDocument().createElement(elementString);
commonXmlElement.setAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB, commonElement.getResource().getName());
commonXmlElement.setAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB, commonElement.getTraceType());
Node commonNode = tmfNode.appendChild(commonXmlElement);
for (TracePackageElement element : tracePackageElement.getChildren()) {
ModalContext.checkCanceled(monitor);
if (!element.isChecked()) {
continue;
}
if (element instanceof TracePackageSupplFilesElement) {
exportSupplementaryFiles(monitor, commonNode, commonElement, (TracePackageSupplFilesElement) element);
} else if (element instanceof TracePackageBookmarkElement) {
exportBookmarks(monitor, commonNode, (TracePackageBookmarkElement) element);
} else if (element instanceof TracePackageFilesElement && commonElement instanceof TmfTraceElement) {
exportTraceFiles(monitor, commonNode, (TracePackageFilesElement) element);
}
monitor.worked(1);
}
return commonNode;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class TracePackageImportOperation method deleteExistingTraces.
private IStatus deleteExistingTraces(IProgressMonitor progressMonitor) {
for (TracePackageElement packageElement : fImportTraceElements) {
TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
if (!isFilesChecked(traceElement)) {
continue;
}
TmfCommonProjectElement projectElement = getMatchingProjectElement(traceElement);
try {
if (projectElement instanceof TmfExperimentElement) {
Display.getDefault().syncExec(() -> projectElement.closeEditors());
projectElement.deleteSupplementaryFolder();
projectElement.getResource().delete(true, SubMonitor.convert(progressMonitor));
} else if (projectElement instanceof TmfTraceElement) {
((TmfTraceElement) projectElement).delete(SubMonitor.convert(progressMonitor), true);
}
} catch (CoreException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e);
}
}
return Status.OK_STATUS;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class ImportTracePackageWizardPage method processTrace.
private void processTrace(List<TracePackageExperimentElement> experimentElements, TracePackageTraceElement traceElement, Map<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentTracesMap, List<TracePackageTraceElement> unhandledTraces) {
boolean isAlone = traceExists(traceElement);
for (TracePackageExperimentElement experimentElement : experimentElements) {
List<String> tracesPath = experimentElement.getExpTraces();
if (traceExists(traceElement) && tracesPath.contains(traceElement.getDestinationElementPath())) {
isAlone = false;
List<TracePackageTraceElement> traces = experimentTracesMap.get(experimentElement);
if (traces == null) {
traces = new ArrayList<>();
}
traces.add(traceElement);
experimentTracesMap.put(experimentElement, traces);
}
}
if (isAlone) {
unhandledTraces.add(traceElement);
}
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class ImportTracePackageWizardPage method handleTracesConflict.
private boolean handleTracesConflict(List<TracePackageTraceElement> traceElements) {
boolean noToAll = false;
for (TracePackageTraceElement traceElement : traceElements) {
if (noToAll) {
uncheckTraceElement(traceElement);
} else {
int returnCode = promptForTraceOverwrite(traceElement);
// constant for that.
if (returnCode < 0) {
return false;
}
final String[] response = new String[] { IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.YES_LABEL };
if (response[returnCode].equals(IDialogConstants.NO_TO_ALL_LABEL)) {
noToAll = true;
uncheckTraceElement(traceElement);
} else if (response[returnCode].equals(IDialogConstants.NO_LABEL)) {
uncheckTraceElement(traceElement);
}
}
}
return true;
}
Aggregations