changeset 155:a9bcccbbf05a

JMC-4469:Adding a page from properties view Summary:Create a page from selected events by right clicking the properties view Reviewed By: Hirt, almac
author kdobson
date Thu, 02 May 2019 11:03:30 -0400
parents 4f77e6262cb3
children f927bf19d4f0
files application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/JfrPropertySheet.java application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/common/DataPageToolkit.java application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/pages/EventBrowserPage.java
diffstat 3 files changed, 34 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/JfrPropertySheet.java	Thu May 02 11:06:51 2019 -0400
+++ b/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/JfrPropertySheet.java	Thu May 02 11:03:30 2019 -0400
@@ -36,6 +36,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -51,6 +52,8 @@
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
 import org.eclipse.jface.viewers.ISelection;
@@ -89,6 +92,7 @@
 import org.openjdk.jmc.common.util.TypeHandling;
 import org.openjdk.jmc.flightrecorder.JfrAttributes;
 import org.openjdk.jmc.flightrecorder.ui.common.DataPageToolkit;
+import org.openjdk.jmc.flightrecorder.ui.common.ImageConstants;
 import org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages;
 import org.openjdk.jmc.flightrecorder.ui.preferences.PreferenceKeys;
 import org.openjdk.jmc.flightrecorder.ui.selection.FlavoredSelectionBase;
@@ -115,10 +119,12 @@
 // FIXME: fields - units - filters - icons etc. should be handled more properly
 public class JfrPropertySheet extends Page implements IPropertySheetPage {
 
+	private static final ImageDescriptor NEW_PAGE_ICON = FlightRecorderUI.getDefault()
+			.getMCImageDescriptor(ImageConstants.ICON_NEW_PAGE);
 	private static final String HELP_CONTEXT_ID = FlightRecorderUI.PLUGIN_ID + ".JfrPropertiesView"; //$NON-NLS-1$
 	private static final Object TOO_MANY_VALUES = new Object();
 	private static final PropertySheetRow CALCULATING = new PropertySheetRow(null, null);
-
+	private static Set<IType<?>> selectedTypes = Collections.emptySet();
 	private static class PropertySheetRowSelection extends FlavoredSelectionBase {
 
 		private final PropertySheetRow row;
@@ -298,10 +304,12 @@
 					} else if (value == TOO_MANY_VALUES) {
 						return Messages.JFR_PROPERTIES_TOO_MANY_VALUES;
 					}
+					updateSelectedTypes(value);
 					return getValueString(value);
 				};
 
 				// FIXME: Merge with TypeHandling.getValueString
+				@SuppressWarnings("unchecked")
 				private String getValueString(Object value) {
 					if (value instanceof IItemCollection) {
 						return itemCollectionDescription((IItemCollection) value);
@@ -312,9 +320,10 @@
 						return "[" + values[0].getName() + " ... " //$NON-NLS-1$ //$NON-NLS-2$
 								+ values[values.length - 1].getName() + "]"; //$NON-NLS-1$
 					} else if (value instanceof Object[]) {
-
 						return limitedDeepToString((Object[]) value, this::getValueString);
-					} else if (value instanceof Collection) {
+					} else if (value instanceof Collection<?>) {
+						selectedTypes = new HashSet<IType<?>>((Collection<IType<?>>) value)
+							.stream().collect(Collectors.toSet());
 						return limitedDeepToString(((Collection<?>) value).toArray(), this::getValueString);
 					}
 					return TypeHandling.getValueString(value);
@@ -328,8 +337,18 @@
 					}
 					return JfrPropertySheet.getVerboseString(value);
 				};
+			}).build();
 
-			}).build();
+	private static void updateSelectedTypes(Object value) {
+		if (value instanceof IType<?>) {
+			selectedTypes = new HashSet<IType<?>>();
+			selectedTypes.add((IType<?>) value);
+		}
+		else if (value instanceof Collection<?>) {
+			selectedTypes = new HashSet<IType<?>>((Collection<IType<?>>) value)
+					.stream().collect(Collectors.toSet());
+		}
+	}
 
 	private static String limitedDeepToString(Object[] array, Function<Object, String> valueToStringProvider) {
 		return limitedDeepToString(array, new StringBuilder(), true, valueToStringProvider);
@@ -443,6 +462,9 @@
 			return null;
 		};
 		// FIXME: Break out to other place where these actions are added to menus
+		IAction addPageAction = ActionToolkit.action(() -> DataPageToolkit.addPage(selectedTypes),
+				Messages.EventBrowserPage_NEW_PAGE_USING_TYPES_ACTION, NEW_PAGE_ICON);
+		mm.appendToGroup(MCContextMenuManager.GROUP_NEW, addPageAction);
 		mm.appendToGroup(MCContextMenuManager.GROUP_EDIT,
 				ActionToolkit.forListSelection(viewer, Messages.STORE_SELECTION_ACTION, false,
 						actionProvider.apply(controller.getSelectionStore()::addSelection)));
--- a/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/common/DataPageToolkit.java	Thu May 02 11:06:51 2019 -0400
+++ b/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/common/DataPageToolkit.java	Thu May 02 11:03:30 2019 -0400
@@ -128,10 +128,13 @@
 import org.openjdk.jmc.flightrecorder.ui.IPageContainer;
 import org.openjdk.jmc.flightrecorder.ui.ItemCollectionToolkit;
 import org.openjdk.jmc.flightrecorder.ui.ItemIterableToolkit;
+import org.openjdk.jmc.flightrecorder.ui.PageManager;
 import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogram.CompositeKeyHistogramBuilder;
 import org.openjdk.jmc.flightrecorder.ui.common.ItemList.ItemListBuilder;
 import org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages;
 import org.openjdk.jmc.flightrecorder.ui.overview.ResultOverview;
+import org.openjdk.jmc.flightrecorder.ui.pages.itemhandler.ItemHandlerPage;
+import org.openjdk.jmc.flightrecorder.ui.pages.itemhandler.ItemHandlerPage.ItemHandlerUiStandIn;
 import org.openjdk.jmc.flightrecorder.ui.selection.IFilterFlavor;
 import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStore.SelectionStoreEntry;
 import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStoreActionToolkit;
@@ -1151,4 +1154,8 @@
 				&& JfrAttributes.START_TIME.getAccessor(type) != JfrAttributes.END_TIME.getAccessor(type);
 	}
 
+	public static void addPage(Set<IType<?>> selectedTypes) {
+		PageManager pm = FlightRecorderUI.getDefault().getPageManager();
+		pm.makeRoot(pm.createPage(ItemHandlerPage.Factory.class, new ItemHandlerUiStandIn(selectedTypes)));
+	}
 }
--- a/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/pages/EventBrowserPage.java	Thu May 02 11:06:51 2019 -0400
+++ b/application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/pages/EventBrowserPage.java	Thu May 02 11:03:30 2019 -0400
@@ -185,7 +185,7 @@
 			toolkit.adapt(treeSash);
 			typeFilterTree = DataPageToolkit.buildEventTypeTree(treeSash, toolkit, this::onTypeChange, false);
 			MCContextMenuManager mm = typeFilterTree.getMenuManager();
-			IAction addPageAction = ActionToolkit.action(this::addPage,
+			IAction addPageAction = ActionToolkit.action(() -> DataPageToolkit.addPage(selectedTypes),
 					Messages.EventBrowserPage_NEW_PAGE_USING_TYPES_ACTION, NEW_PAGE_ICON);
 			mm.appendToGroup(MCContextMenuManager.GROUP_NEW, addPageAction);
 
@@ -230,11 +230,6 @@
 			list.getManager().setSelectionState(tableSelection);
 		}
 
-		private void addPage() {
-			PageManager pm = FlightRecorderUI.getDefault().getPageManager();
-			pm.makeRoot(pm.createPage(ItemHandlerPage.Factory.class, new ItemHandlerUiStandIn(selectedTypes)));
-		}
-
 		private void setTypesWithoutEvents(boolean checked) {
 			showTypesWithoutEvents = checked;
 			refreshTree();