use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.
the class ColorSettingsXML method save.
/**
* Saves the given color settings to file.
*
* @param pathName
* A file name with path
* @param colorSettings
* An array of color settings to save.
*/
public static void save(String pathName, ColorSetting[] colorSettings) {
try {
DocumentBuilder documentBuilder = XmlUtils.newSafeDocumentBuilderFactory().newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element rootElement = document.createElement(COLOR_SETTINGS_TAG);
document.appendChild(rootElement);
for (ColorSetting colorSetting : colorSettings) {
Element colorSettingElement = document.createElement(COLOR_SETTING_TAG);
rootElement.appendChild(colorSettingElement);
RGB foreground = colorSetting.getForegroundRGB();
if (foreground != null) {
Element fgElement = document.createElement(FG_TAG);
colorSettingElement.appendChild(fgElement);
setElementColor(fgElement, foreground);
}
RGB background = colorSetting.getBackgroundRGB();
if (background != null) {
Element bgElement = document.createElement(BG_TAG);
colorSettingElement.appendChild(bgElement);
setElementColor(bgElement, background);
}
Element tickColorElement = document.createElement(TICK_TAG);
colorSettingElement.appendChild(tickColorElement);
RGB tickColor = colorSetting.getTickColorRGB();
setElementColor(tickColorElement, tickColor);
ITmfFilterTreeNode filter = colorSetting.getFilter();
if (filter != null) {
Element filterElement = document.createElement(FILTER_TAG);
colorSettingElement.appendChild(filterElement);
TmfFilterXMLWriter.buildXMLTree(document, filter, filterElement);
}
}
Transformer transformer = XmlUtils.newSecureTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new File(pathName));
transformer.transform(source, result);
} catch (ParserConfigurationException | TransformerException e) {
// $NON-NLS-1$
Activator.getDefault().logError("Error saving color xml file: " + pathName, e);
}
}
use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.
the class CutHandler method getSelection.
@Override
protected ISelection getSelection(FilterView tcv) {
ISelection sel = super.getSelection(tcv);
if (sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
Object o = selection.getFirstElement();
if (o instanceof ITmfFilterTreeNode) {
ITmfFilterTreeNode node = (ITmfFilterTreeNode) o;
node = node.remove();
tcv.refresh();
return new StructuredSelection(node);
}
}
return sel;
}
use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.
the class DeleteHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Check if we are closing down
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return null;
}
IWorkbenchPage page = window.getActivePage();
FilterView part = (FilterView) page.getActivePart();
ISelection sel = part.getViewSite().getSelectionProvider().getSelection();
if (sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
Object o = selection.getFirstElement();
if (o instanceof ITmfFilterTreeNode) {
ITmfFilterTreeNode node = (ITmfFilterTreeNode) o;
node.remove();
part.refresh();
}
}
return null;
}
use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.
the class FilterDropTargetAdapter method isAncestor.
/**
* Returns <code>true</code> if droppedNode is an ancestor of node.
*
* @param droppedNode
* the ITmfFilterTreeNode to drop or paste
* @param node
* the ITmfFilterTreeNode receiving a new child
* @return <code>true</code> if droppedNode is and ancestor of node,
* <code>false</code> otherwise.
*/
private static boolean isAncestor(ITmfFilterTreeNode droppedNode, ITmfFilterTreeNode node) {
ITmfFilterTreeNode tmp = node;
while (tmp != null) {
ITmfFilterTreeNode n = tmp.getParent();
if (n == droppedNode) {
return true;
}
tmp = n;
}
return false;
}
use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.
the class FilterDropTargetAdapter method dropAccept.
@Override
public void dropAccept(DropTargetEvent event) {
ITmfFilterTreeNode treeNodeToDrop = null;
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
treeNodeToDrop = FilterEditUtils.getTransferredTreeNode();
}
if (treeNodeToDrop == null) {
// should never occur
event.detail = DND.DROP_NONE;
return;
}
if (event.item instanceof TreeItem) {
Object data = event.item.getData();
if (data instanceof ITmfFilterTreeNode) {
ITmfFilterTreeNode node = (ITmfFilterTreeNode) data;
if (node.getValidChildren().contains(treeNodeToDrop.getNodeName())) {
if (isAncestor(treeNodeToDrop, node) && event.detail != DND.DROP_COPY) {
// do nothing in this case
event.detail = DND.DROP_NONE;
}
return;
}
}
} else {
// accept only TmfFilterNode
if (!TmfFilterNode.NODE_NAME.equals(treeNodeToDrop.getNodeName())) {
event.detail = DND.DROP_NONE;
}
return;
}
event.detail = DND.DROP_NONE;
return;
}
Aggregations