From 9194376ff4c21bcbd7062150e2bfc97c6844ebd6 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Wed, 14 Nov 2012 16:29:01 +0400 Subject: [PATCH] Bug 360314: Improve diagnostics of invalid selections in OS Resources view. Change-Id: I1a43dbf5bd58cbaaf05a21f9b3936fa7303faa37 Reviewed-on: https://git.eclipse.org/r/8685 Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../dsf/gdb/internal/ui/osview/Messages.java | 1 + .../internal/ui/osview/Messages.properties | 3 +- .../internal/ui/osview/OSResourcesView.java | 61 +++++++++++++------ 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.java index ae708ab7f14..1654ca6e03d 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.java @@ -29,6 +29,7 @@ public class Messages extends NLS { public static String OSView_12; public static String OSView_13; public static String OSView_14; + public static String OSView_15; static { // initialize resource bundle NLS.initializeMessages(Messages.class.getName(), Messages.class); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.properties index 79bea302796..184a619b1de 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/Messages.properties @@ -9,7 +9,7 @@ # Vladimir Prus (Mentor Graphics) - initial API and implementation ############################################################################### OSView_3=Refresh -OSView_4=Invalid debug session selected. +OSView_4=Invalid debug object selected. Please select a process, thread or frame inside DSF GDB debug session. OSView_5=Please select resource class. OSView_6=Fetching data... OSView_7=No data has been fetched yet. Fetch now. @@ -20,3 +20,4 @@ OSView_11=Determining available OS resource classes... OSView_12=No data has been fetched yet. Target is busy. OSView_13=Waiting for the debug session to initialize. OSView_14=Objects from different debug sessions are selected. +OSView_15=No debug session is selected. diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/OSResourcesView.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/OSResourcesView.java index 5e5f2a7cc5a..8306f3dc224 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/OSResourcesView.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/osview/OSResourcesView.java @@ -82,6 +82,8 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded // Indicates that we've selected objects from different debug sessions. boolean fMultiple = false; + // Indicates that we have selected object with a wrong type + boolean fWrongType = false; // UI objects @@ -225,14 +227,20 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded ICommandControlDMContext context = null; fMultiple = false; + fWrongType = false; if (s instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) s; if (ss.size() > 0) { @SuppressWarnings("rawtypes") Iterator i = ss.iterator(); context = getCommandControlContext(i.next()); + if (context == null) + fWrongType = true; + while (i.hasNext()) { - ICommandControlDMContext nextContext = getCommandControlContext(i.next()); + ICommandControlDMContext nextContext = getCommandControlContext(i.next()); + if (nextContext == null) + fWrongType = true; if (nextContext == null && context != null || nextContext != null && context == null || nextContext != null && context != null && !nextContext.equals(context)) @@ -300,18 +308,13 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded public void update() { // Note that fSessionData always calls the listener in // UI thread, so we can directly call 'update' here. - OSResourcesView.this.update(); + OSResourcesView.this.updateSessionDataContents(); } }, fViewer.getControl()); } } - - if (newSessionData != fSessionData) - { - fSessionData = newSessionData; - update(); - } + update(newSessionData); } @Override @@ -323,7 +326,39 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded } } - private void update() { + // Update UI to showing new session data. If this session data is already + // shown, does nothing. + private void update(SessionOSData newSessionData) + { + if (fViewer == null || fViewer.getControl() == null) + return; + + if (fViewer.getControl().isDisposed()) + return; + + if (newSessionData == null) + { + fSessionData = null; + if (fMultiple) + hideTable(Messages.OSView_14); + else if (fWrongType) + hideTable(Messages.OSView_4); + else + hideTable(Messages.OSView_15); + fResourceClassEditor.setEnabled(false); + fRefreshAction.setEnabled(false); + return; + } + + if (newSessionData != fSessionData) { + fSessionData = newSessionData; + updateSessionDataContents(); + } + } + + // Update the UI according to actual content of fSessionData, + // which must be not null. + private void updateSessionDataContents() { if (fViewer == null || fViewer.getControl() == null) return; @@ -331,14 +366,6 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded if (fViewer.getControl().isDisposed()) return; - if (fSessionData == null) - { - hideTable(fMultiple ? Messages.OSView_14 : Messages.OSView_4); - fResourceClassEditor.setEnabled(false); - fRefreshAction.setEnabled(false); - return; - } - boolean enable = fSessionData.canFetchData(); fRefreshAction.setEnabled(enable); fResourceClass = fResourceClassEditor.updateClasses(fSessionData.getResourceClasses());