use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class TracePackageImportOperation method importBookmarks.
private void importBookmarks(IResource traceRes, TracePackageTraceElement traceElement, IProgressMonitor monitor) {
for (TracePackageElement o : traceElement.getChildren()) {
if (o instanceof TracePackageBookmarkElement && o.isChecked()) {
// Get element
IFile bookmarksFile = null;
TmfCommonProjectElement projectElement = getMatchingProjectElement(traceElement);
if (projectElement != null) {
try {
bookmarksFile = projectElement.createBookmarksFile(monitor);
// Make sure that if a bookmark is double-clicked first
// before opening the trace, it opens the right editor
// Get the editor id from the extension point
String traceEditorId = projectElement.getEditorId();
final String editorId = (traceEditorId != null) ? traceEditorId : TmfEventsEditor.ID;
IDE.setDefaultEditor(bookmarksFile, editorId);
} catch (CoreException e) {
Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmarkFile, traceRes.getName()), e);
}
}
if (bookmarksFile == null) {
break;
}
TracePackageBookmarkElement bookmarkElement = (TracePackageBookmarkElement) o;
List<Map<String, String>> bookmarks = bookmarkElement.getBookmarks();
for (Map<String, String> attrs : bookmarks) {
IMarker createMarker = null;
try {
createMarker = bookmarksFile.createMarker(IMarker.BOOKMARK);
} catch (CoreException e) {
Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmark, traceRes.getName()), e);
}
if (createMarker != null && createMarker.exists()) {
try {
for (Entry<String, String> entry : attrs.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key.equals(IMarker.LOCATION)) {
try {
/* try location as an integer for backward compatibility */
createMarker.setAttribute(IMarker.LOCATION, Integer.parseInt(value));
} catch (NumberFormatException e) {
createMarker.setAttribute(IMarker.LOCATION, value);
}
} else {
createMarker.setAttribute(key, value);
}
}
} catch (CoreException e) {
Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmark, traceRes.getName()), e);
}
}
}
}
}
monitor.worked(1);
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method writeProfiles.
private boolean writeProfiles(List<RemoteImportProfileElement> profiles, String path) {
try {
String contents = RemoteImportProfilesWriter.writeProfilesToXML(profiles.toArray(new TracePackageElement[0]));
File file = new File(path);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(contents);
return true;
}
} catch (IOException | ParserConfigurationException | TransformerException e) {
MessageDialog.openError(getShell(), RemoteMessages.RemoteProfilesPreferencePage_ErrorWritingProfile, e.getMessage());
}
return false;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method copyElement.
private TracePackageElement copyElement(TracePackageElement parent, TracePackageElement element) {
TracePackageElement copy = null;
if (element instanceof RemoteImportProfileElement) {
RemoteImportProfileElement source = (RemoteImportProfileElement) element;
copy = new RemoteImportProfileElement(parent, source.getProfileName());
} else if (element instanceof RemoteImportConnectionNodeElement) {
RemoteImportConnectionNodeElement source = (RemoteImportConnectionNodeElement) element;
copy = new RemoteImportConnectionNodeElement(parent, source.getName(), source.getURI());
} else if (element instanceof RemoteImportTraceGroupElement) {
RemoteImportTraceGroupElement source = (RemoteImportTraceGroupElement) element;
copy = new RemoteImportTraceGroupElement(parent, source.getRootImportPath());
((RemoteImportTraceGroupElement) copy).setRecursive(source.isRecursive());
} else if (element instanceof TracePackageTraceElement) {
TracePackageTraceElement source = (TracePackageTraceElement) element;
copy = new TracePackageTraceElement(parent, source.getImportName(), source.getTraceType());
} else if (element instanceof TracePackageFilesElement) {
TracePackageFilesElement source = (TracePackageFilesElement) element;
copy = new TracePackageFilesElement(parent, source.getFileName());
}
for (TracePackageElement child : element.getChildren()) {
copyElement(copy, child);
}
return copy;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method readProfiles.
private static List<RemoteImportProfileElement> readProfiles(String path, IProgressMonitor monitor) {
final ExtractRemoteProfilesOperation op = new ExtractRemoteProfilesOperation(path);
op.run(monitor);
List<RemoteImportProfileElement> profiles = new ArrayList<>();
if (!op.getStatus().isOK()) {
return profiles;
}
TracePackageElement[] resultElements = op.getResultElements();
if (resultElements != null) {
for (TracePackageElement element : resultElements) {
if (element instanceof RemoteImportProfileElement) {
profiles.add((RemoteImportProfileElement) element);
}
}
}
return profiles;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
composite.setLayoutData(gd);
GridLayout gl = new GridLayout(2, false);
composite.setLayout(gl);
PatternFilter patternFilter = new PatternFilter() {
// show all children of matching profiles or profiles with matching connection node
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
TreeViewer treeViewer = (TreeViewer) viewer;
TracePackageContentProvider contentProvider = (TracePackageContentProvider) treeViewer.getContentProvider();
Object parentElement = element;
while (!(parentElement instanceof RemoteImportProfileElement)) {
parentElement = contentProvider.getParent(parentElement);
if (parentElement instanceof TracePackageTraceElement) {
// don't show children of trace element
return false;
}
}
RemoteImportProfileElement profile = (RemoteImportProfileElement) parentElement;
if (super.isLeafMatch(viewer, profile)) {
return true;
}
for (Object child : contentProvider.getChildren(profile)) {
if ((child instanceof RemoteImportConnectionNodeElement) && (super.isLeafMatch(viewer, child))) {
return true;
}
}
return false;
}
};
final FilteredTree filteredTree = new FilteredTree(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 0;
filteredTree.setLayoutData(gd);
final TreeViewer treeViewer = filteredTree.getViewer();
fTreeViewer = treeViewer;
treeViewer.setContentProvider(new TracePackageContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof ArrayList) {
return ((ArrayList<?>) inputElement).toArray();
}
return super.getElements(inputElement);
}
@Override
public boolean hasChildren(Object element) {
if (element instanceof TracePackageTraceElement) {
return false;
}
return super.hasChildren(element);
}
});
treeViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof TracePackageTraceElement) {
for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
if (files instanceof TracePackageFilesElement) {
return ((TracePackageFilesElement) files).getFileName();
}
}
} else if (element instanceof TracePackageElement) {
return ((TracePackageElement) element).getText();
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (element instanceof TracePackageTraceElement) {
for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
return files.getImage();
}
} else if (element instanceof TracePackageElement) {
return ((TracePackageElement) element).getImage();
}
return super.getImage(element);
}
});
treeViewer.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
TracePackageElement element = (TracePackageElement) (selection.size() == 1 ? selection.getFirstElement() : null);
fDetailsPanel.refreshDetailsPanel(element);
enableButtons(selection);
fSelectedProfileName = null;
while (element != null) {
if (element instanceof RemoteImportProfileElement) {
fSelectedProfileName = ((RemoteImportProfileElement) element).getProfileName();
}
element = element.getParent();
}
});
createGlobalActions();
createContextMenu();
fProfiles = readProfiles(PROFILE_FILE_PATH, new NullProgressMonitor());
treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
treeViewer.setInput(fProfiles);
treeViewer.expandAll();
Composite buttonBar = createVerticalButtonBar(composite);
gd = new GridData(SWT.CENTER, SWT.BEGINNING, false, false);
gd.verticalIndent = filteredTree.getFilterControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y + gl.verticalSpacing;
buttonBar.setLayoutData(gd);
enableButtons((IStructuredSelection) treeViewer.getSelection());
Composite details = new Composite(composite, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
details.setLayoutData(gd);
gl = new GridLayout(2, false);
gl.marginWidth = 0;
details.setLayout(gl);
Label label = new Label(details, SWT.NONE);
label.setText(RemoteMessages.RemoteProfilesPreferencePage_DetailsPanelLabel);
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1);
label.setLayoutData(gd);
fDetailsPanel = new DetailsPanel(details);
validate();
for (RemoteImportProfileElement profile : fProfiles) {
if (profile.getProfileName().equals(fSelectedProfileName)) {
fTreeViewer.setSelection(new StructuredSelection(profile));
}
}
Dialog.applyDialogFont(composite);
return composite;
}
Aggregations