< prev index next >

application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/common/DataPageToolkit.java

Print this page


   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.

   3  * 
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * The contents of this file are subject to the terms of either the Universal Permissive License
   7  * v 1.0 as shown at http://oss.oracle.com/licenses/upl
   8  *
   9  * or the following license:
  10  *
  11  * Redistribution and use in source and binary forms, with or without modification, are permitted
  12  * provided that the following conditions are met:
  13  * 
  14  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions
  15  * and the following disclaimer.
  16  * 
  17  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
  18  * conditions and the following disclaimer in the documentation and/or other materials provided with
  19  * the distribution.
  20  * 
  21  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to
  22  * endorse or promote products derived from this software without specific prior written permission.


 122 import org.openjdk.jmc.flightrecorder.jdk.JdkAttributes;
 123 import org.openjdk.jmc.flightrecorder.jdk.JdkFilters;
 124 import org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs;
 125 import org.openjdk.jmc.flightrecorder.rules.Result;
 126 import org.openjdk.jmc.flightrecorder.rules.Severity;
 127 import org.openjdk.jmc.flightrecorder.ui.FlightRecorderUI;
 128 import org.openjdk.jmc.flightrecorder.ui.IPageContainer;
 129 import org.openjdk.jmc.flightrecorder.ui.ItemCollectionToolkit;
 130 import org.openjdk.jmc.flightrecorder.ui.ItemIterableToolkit;
 131 import org.openjdk.jmc.flightrecorder.ui.PageManager;
 132 import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogram.CompositeKeyHistogramBuilder;
 133 import org.openjdk.jmc.flightrecorder.ui.common.ItemList.ItemListBuilder;
 134 import org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages;
 135 import org.openjdk.jmc.flightrecorder.ui.overview.ResultOverview;
 136 import org.openjdk.jmc.flightrecorder.ui.pages.itemhandler.ItemHandlerPage;
 137 import org.openjdk.jmc.flightrecorder.ui.pages.itemhandler.ItemHandlerPage.ItemHandlerUiStandIn;
 138 import org.openjdk.jmc.flightrecorder.ui.selection.IFilterFlavor;
 139 import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStore.SelectionStoreEntry;
 140 import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStoreActionToolkit;
 141 import org.openjdk.jmc.ui.charts.AWTChartToolkit.IColorProvider;

 142 import org.openjdk.jmc.ui.charts.IQuantitySeries;
 143 import org.openjdk.jmc.ui.charts.ISpanSeries;
 144 import org.openjdk.jmc.ui.charts.IXDataRenderer;
 145 import org.openjdk.jmc.ui.charts.QuantitySeries;
 146 import org.openjdk.jmc.ui.charts.RendererToolkit;
 147 import org.openjdk.jmc.ui.charts.SpanRenderer;
 148 import org.openjdk.jmc.ui.charts.SubdividedQuantityRange;
 149 import org.openjdk.jmc.ui.charts.XYChart;
 150 import org.openjdk.jmc.ui.charts.XYDataRenderer;
 151 import org.openjdk.jmc.ui.charts.XYQuantities;
 152 import org.openjdk.jmc.ui.column.ColumnMenusFactory;
 153 import org.openjdk.jmc.ui.column.TableSettings;
 154 import org.openjdk.jmc.ui.column.TableSettings.ColumnSettings;
 155 import org.openjdk.jmc.ui.handlers.ActionToolkit;
 156 import org.openjdk.jmc.ui.handlers.MCContextMenuManager;
 157 import org.openjdk.jmc.ui.misc.ChartCanvas;

 158 import org.openjdk.jmc.ui.misc.CompositeToolkit;
 159 import org.openjdk.jmc.ui.misc.DisplayToolkit;
 160 import org.openjdk.jmc.ui.misc.FilterEditor;
 161 import org.openjdk.jmc.ui.misc.FilterEditor.AttributeValueProvider;
 162 import org.openjdk.jmc.ui.misc.OverlayImageDescriptor;
 163 import org.openjdk.jmc.ui.misc.SWTColorToolkit;
 164 
 165 public class DataPageToolkit {
 166 
 167         public static final IColorProvider<IItem> ITEM_COLOR = item -> TypeLabelProvider
 168                         .getColorOrDefault(item.getType().getIdentifier());
 169 
 170         public static final IColorProvider<IItem> getAttributeValueColor(final IAttribute<?> attribute) {
 171                 return new IColorProvider<IItem>() {
 172 
 173                         @Override
 174                         public Color getColor(IItem item) {
 175                                 IMemberAccessor<?, IItem> accessor = attribute.getAccessor(ItemToolkit.getItemType(item));
 176                                 Object attributeValue = accessor != null ? accessor.getMember(item) : null;
 177                                 // FIXME: Should we include the type or not?


 295          *            A query containing only {@code IAttribute<IQuantity>} attributes. Queries
 296          *            containing non-quantity attributes are not supported and may cause
 297          *            ClassCastExceptions later when the attributes are used.
 298          * @return a stream of the query attributes
 299          */
 300         /*
 301          * FIXME: JMC-5125 - This cast chain is scary and should be reworked.
 302          * 
 303          * If the query contains any non-quantity attributes then there will be a ClassCastException
 304          * later when the attributes are used to extract values.
 305          */
 306         @SuppressWarnings({"unchecked", "rawtypes"})
 307         public static Stream<IAttribute<IQuantity>> getQuantityAttributes(IItemQuery q) {
 308                 return (Stream) q.getAttributes().stream();
 309         }
 310 
 311         public static void setChart(ChartCanvas canvas, XYChart chart, Consumer<IItemCollection> selectionListener) {
 312                 setChart(canvas, chart, selectionListener, null);
 313         }
 314 




 315         public static void setChart(
 316                 ChartCanvas canvas, XYChart chart, Consumer<IItemCollection> selectionListener,
 317                 Consumer<IRange<IQuantity>> selectRangeConsumer) {
 318                 IMenuManager contextMenu = canvas.getContextMenu();
 319                 contextMenu.removeAll();
 320                 canvas.getContextMenu().add(new Action(Messages.CHART_ZOOM_TO_SELECTED_RANGE) {
 321                         @Override
 322                         public void run() {
 323                                 IQuantity selectionStart = chart.getSelectionStart();
 324                                 IQuantity selectionEnd = chart.getSelectionEnd();
 325                                 if (selectionStart == null || selectionEnd == null) {
 326                                         chart.clearVisibleRange();
 327                                 } else {
 328                                         chart.setVisibleRange(selectionStart, selectionEnd);
 329                                 }
 330                                 canvas.redrawChart();































 331                         }
 332                 });
 333 
 334                 canvas.setSelectionListener(() -> {
 335                         selectionListener.accept(ItemRow.getRangeSelection(chart, JfrAttributes.LIFETIME));
 336                         IQuantity start = chart.getSelectionStart();
 337                         IQuantity end = chart.getSelectionEnd();
 338                         if (selectRangeConsumer != null) {
 339                                 selectRangeConsumer
 340                                                 .accept(start != null && end != null ? QuantityRange.createWithEnd(start, end) : null);
 341                         }
 342                 });
 343                 canvas.setChart(chart);
 344         }
 345 
 346         public static void setChart(
 347                 ChartCanvas canvas, XYChart chart, IAttribute<IQuantity> selectionAttribute,
 348                 Consumer<IItemCollection> selectionListener) {
 349                 IMenuManager contextMenu = canvas.getContextMenu();
 350                 contextMenu.removeAll();


   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2019, Red Hat Inc. All rights reserved.
   4  *
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * The contents of this file are subject to the terms of either the Universal Permissive License
   8  * v 1.0 as shown at http://oss.oracle.com/licenses/upl
   9  *
  10  * or the following license:
  11  *
  12  * Redistribution and use in source and binary forms, with or without modification, are permitted
  13  * provided that the following conditions are met:
  14  *
  15  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions
  16  * and the following disclaimer.
  17  *
  18  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
  19  * conditions and the following disclaimer in the documentation and/or other materials provided with
  20  * the distribution.
  21  *
  22  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to
  23  * endorse or promote products derived from this software without specific prior written permission.


 123 import org.openjdk.jmc.flightrecorder.jdk.JdkAttributes;
 124 import org.openjdk.jmc.flightrecorder.jdk.JdkFilters;
 125 import org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs;
 126 import org.openjdk.jmc.flightrecorder.rules.Result;
 127 import org.openjdk.jmc.flightrecorder.rules.Severity;
 128 import org.openjdk.jmc.flightrecorder.ui.FlightRecorderUI;
 129 import org.openjdk.jmc.flightrecorder.ui.IPageContainer;
 130 import org.openjdk.jmc.flightrecorder.ui.ItemCollectionToolkit;
 131 import org.openjdk.jmc.flightrecorder.ui.ItemIterableToolkit;
 132 import org.openjdk.jmc.flightrecorder.ui.PageManager;
 133 import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogram.CompositeKeyHistogramBuilder;
 134 import org.openjdk.jmc.flightrecorder.ui.common.ItemList.ItemListBuilder;
 135 import org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages;
 136 import org.openjdk.jmc.flightrecorder.ui.overview.ResultOverview;
 137 import org.openjdk.jmc.flightrecorder.ui.pages.itemhandler.ItemHandlerPage;
 138 import org.openjdk.jmc.flightrecorder.ui.pages.itemhandler.ItemHandlerPage.ItemHandlerUiStandIn;
 139 import org.openjdk.jmc.flightrecorder.ui.selection.IFilterFlavor;
 140 import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStore.SelectionStoreEntry;
 141 import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStoreActionToolkit;
 142 import org.openjdk.jmc.ui.charts.AWTChartToolkit.IColorProvider;
 143 import org.openjdk.jmc.ui.charts.ChartFilterControlBar;
 144 import org.openjdk.jmc.ui.charts.IQuantitySeries;
 145 import org.openjdk.jmc.ui.charts.ISpanSeries;
 146 import org.openjdk.jmc.ui.charts.IXDataRenderer;
 147 import org.openjdk.jmc.ui.charts.QuantitySeries;
 148 import org.openjdk.jmc.ui.charts.RendererToolkit;
 149 import org.openjdk.jmc.ui.charts.SpanRenderer;
 150 import org.openjdk.jmc.ui.charts.SubdividedQuantityRange;
 151 import org.openjdk.jmc.ui.charts.XYChart;
 152 import org.openjdk.jmc.ui.charts.XYDataRenderer;
 153 import org.openjdk.jmc.ui.charts.XYQuantities;
 154 import org.openjdk.jmc.ui.column.ColumnMenusFactory;
 155 import org.openjdk.jmc.ui.column.TableSettings;
 156 import org.openjdk.jmc.ui.column.TableSettings.ColumnSettings;
 157 import org.openjdk.jmc.ui.handlers.ActionToolkit;
 158 import org.openjdk.jmc.ui.handlers.MCContextMenuManager;
 159 import org.openjdk.jmc.ui.misc.ChartCanvas;
 160 import org.openjdk.jmc.ui.misc.ChartTextCanvas;
 161 import org.openjdk.jmc.ui.misc.CompositeToolkit;
 162 import org.openjdk.jmc.ui.misc.DisplayToolkit;
 163 import org.openjdk.jmc.ui.misc.FilterEditor;
 164 import org.openjdk.jmc.ui.misc.FilterEditor.AttributeValueProvider;
 165 import org.openjdk.jmc.ui.misc.OverlayImageDescriptor;
 166 import org.openjdk.jmc.ui.misc.SWTColorToolkit;
 167 
 168 public class DataPageToolkit {
 169 
 170         public static final IColorProvider<IItem> ITEM_COLOR = item -> TypeLabelProvider
 171                         .getColorOrDefault(item.getType().getIdentifier());
 172 
 173         public static final IColorProvider<IItem> getAttributeValueColor(final IAttribute<?> attribute) {
 174                 return new IColorProvider<IItem>() {
 175 
 176                         @Override
 177                         public Color getColor(IItem item) {
 178                                 IMemberAccessor<?, IItem> accessor = attribute.getAccessor(ItemToolkit.getItemType(item));
 179                                 Object attributeValue = accessor != null ? accessor.getMember(item) : null;
 180                                 // FIXME: Should we include the type or not?


 298          *            A query containing only {@code IAttribute<IQuantity>} attributes. Queries
 299          *            containing non-quantity attributes are not supported and may cause
 300          *            ClassCastExceptions later when the attributes are used.
 301          * @return a stream of the query attributes
 302          */
 303         /*
 304          * FIXME: JMC-5125 - This cast chain is scary and should be reworked.
 305          * 
 306          * If the query contains any non-quantity attributes then there will be a ClassCastException
 307          * later when the attributes are used to extract values.
 308          */
 309         @SuppressWarnings({"unchecked", "rawtypes"})
 310         public static Stream<IAttribute<IQuantity>> getQuantityAttributes(IItemQuery q) {
 311                 return (Stream) q.getAttributes().stream();
 312         }
 313 
 314         public static void setChart(ChartCanvas canvas, XYChart chart, Consumer<IItemCollection> selectionListener) {
 315                 setChart(canvas, chart, selectionListener, null);
 316         }
 317 
 318         public static void setChart(ChartTextCanvas canvas, XYChart chart, Consumer<IItemCollection> selectionListener) {
 319                 setChart(canvas, chart, selectionListener, null);
 320         }
 321 
 322         public static void setChart(
 323                 ChartCanvas canvas, XYChart chart, Consumer<IItemCollection> selectionListener,
 324                 Consumer<IRange<IQuantity>> selectRangeConsumer) {
 325                 IMenuManager contextMenu = canvas.getContextMenu();
 326                 contextMenu.removeAll();
 327                 canvas.getContextMenu().add(new Action(Messages.CHART_ZOOM_TO_SELECTED_RANGE) {
 328                         @Override
 329                         public void run() {
 330                                 IQuantity selectionStart = chart.getSelectionStart();
 331                                 IQuantity selectionEnd = chart.getSelectionEnd();
 332                                 if (selectionStart == null || selectionEnd == null) {
 333                                         chart.clearVisibleRange();
 334                                 } else {
 335                                         chart.setVisibleRange(selectionStart, selectionEnd);
 336                                 }
 337                                 canvas.redrawChart();
 338                         }
 339                 });
 340 
 341                 canvas.setSelectionListener(() -> {
 342                         selectionListener.accept(ItemRow.getRangeSelection(chart, JfrAttributes.LIFETIME));
 343                         IQuantity start = chart.getSelectionStart();
 344                         IQuantity end = chart.getSelectionEnd();
 345                         if (selectRangeConsumer != null) {
 346                                 selectRangeConsumer
 347                                                 .accept(start != null && end != null ? QuantityRange.createWithEnd(start, end) : null);
 348                         }
 349                 });
 350                 canvas.setChart(chart);
 351         }
 352 
 353         public static void setChart(
 354                 ChartTextCanvas canvas, XYChart chart, Consumer<IItemCollection> selectionListener,
 355                 Consumer<IRange<IQuantity>> selectRangeConsumer) {
 356                 IMenuManager contextMenu = canvas.getContextMenu();
 357                 contextMenu.removeAll();
 358                 canvas.getContextMenu().add(new Action(Messages.CHART_ZOOM_TO_SELECTED_RANGE) {
 359                         @Override
 360                         public void run() {
 361                                 IQuantity selectionStart = chart.getSelectionStart();
 362                                 IQuantity selectionEnd = chart.getSelectionEnd();
 363                                 if (selectionStart == null || selectionEnd == null) {
 364                                         chart.clearVisibleRange();
 365                                 } else {
 366                                         chart.setVisibleRange(selectionStart, selectionEnd);
 367                                 }
 368                                 canvas.redrawChartText();
 369                         }
 370                 });
 371 
 372                 canvas.setSelectionListener(() -> {
 373                         selectionListener.accept(ItemRow.getRangeSelection(chart, JfrAttributes.LIFETIME));
 374                         IQuantity start = chart.getSelectionStart();
 375                         IQuantity end = chart.getSelectionEnd();
 376                         if (selectRangeConsumer != null) {
 377                                 selectRangeConsumer
 378                                                 .accept(start != null && end != null ? QuantityRange.createWithEnd(start, end) : null);
 379                         }
 380                 });
 381                 canvas.setChart(chart);
 382         }
 383 
 384         public static void setChart(
 385                 ChartCanvas canvas, XYChart chart, IAttribute<IQuantity> selectionAttribute,
 386                 Consumer<IItemCollection> selectionListener) {
 387                 IMenuManager contextMenu = canvas.getContextMenu();
 388                 contextMenu.removeAll();


< prev index next >