aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrajesh2013-12-09 12:54:58 (EST)
committerRodrigo Fraxino Araujo2014-01-10 07:10:08 (EST)
commit4614f53ce1923bb9a7a74262b03f25ba49c2326c (patch)
treee038379c906c322776024731c51b7e37f975e901
parent74500a197866acd75ab52189089ffed8389a427f (diff)
downloadorg.eclipse.linuxtools-4614f53ce1923bb9a7a74262b03f25ba49c2326c.zip
org.eclipse.linuxtools-4614f53ce1923bb9a7a74262b03f25ba49c2326c.tar.gz
org.eclipse.linuxtools-4614f53ce1923bb9a7a74262b03f25ba49c2326c.tar.bz2
Oprofile view delete and save default session issuerefs/changes/71/19571/4
we found two issue in oprofile view 1.selecting "Delete session" from the View Menu to delete the current session silently fails. 2.The "Save Default Session" option from the View Menu copies the "current" session to the new session specified by the user, and the OProfile view then has both the current and the new session (duplicates of one another). we fixed both problem. sending it for review Signed-off-by: Brajesh <brrathor@linux.vnet.ibm.com> Change-Id: Ia2398abd2b931c002c0ebaa14a2a0e34de929cfc Reviewed-on: https://git.eclipse.org/r/19571 Reviewed-by: Rodrigo Fraxino Araujo <rfaraujo@linux.vnet.ibm.com> IP-Clean: Rodrigo Fraxino Araujo <rfaraujo@linux.vnet.ibm.com> Tested-by: Rodrigo Fraxino Araujo <rfaraujo@linux.vnet.ibm.com>
-rwxr-xr-x[-rw-r--r--]oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileView.java68
-rwxr-xr-x[-rw-r--r--]oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewDeleteSessionAction.java7
-rwxr-xr-x[-rw-r--r--]oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewSaveDefaultSessionAction.java38
3 files changed, 82 insertions, 31 deletions
diff --git a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileView.java b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileView.java
index e5b75c4..1bc68db 100644..100755
--- a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileView.java
+++ b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileView.java
@@ -6,21 +6,26 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
- *******************************************************************************/
+ * Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
+ *******************************************************************************/
package org.eclipse.linuxtools.internal.oprofile.ui.view;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelRoot;
import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiMessages;
import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiPlugin;
import org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot;
+import org.eclipse.linuxtools.oprofile.ui.model.UiModelSession;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
@@ -32,7 +37,7 @@ import org.eclipse.ui.part.ViewPart;
* The view for the OProfile plugin. Shows the elements gathered by the data model
* in a tree viewer, parsed by the ui model (in the model package). The hierarchy
* (as it is displayed) looks like:
- *
+ *
* UiModelRoot (not shown in the view)
* \_ UiModelEvent
* \_ ...
@@ -51,12 +56,14 @@ import org.eclipse.ui.part.ViewPart;
* \_ UiModelImage
* | \_ ... (see above)
* \_ ...
- *
+ *
* The refreshView() function takes care of launching the data model parsing and
* ui model parsing in a separate thread.
*/
-public class OprofileView extends ViewPart {
+public class OprofileView extends ViewPart implements ISelectionChangedListener {
private TreeViewer viewer;
+ private IAction deleteSessionAction;
+ private IAction saveDefaultSessionAction;
@Override
public void createPartControl(Composite parent) {
@@ -65,30 +72,33 @@ public class OprofileView extends ViewPart {
OprofileUiPlugin.getDefault().setOprofileView(this);
}
-
+
private void createTreeViewer(Composite parent) {
viewer = new TreeViewer(parent, SWT.SINGLE);
viewer.setContentProvider(new OprofileViewContentProvider());
viewer.setLabelProvider(new OprofileViewLabelProvider());
viewer.addDoubleClickListener(new OprofileViewDoubleClickListener());
+ viewer.addSelectionChangedListener(this);
}
private void createActionMenu() {
IMenuManager manager = getViewSite().getActionBars().getMenuManager();
-
+
manager.add(new OprofileViewLogReaderAction());
manager.add(new OprofileViewRefreshAction());
- manager.add(new OprofileViewSaveDefaultSessionAction());
- manager.add(new OprofileViewDeleteSessionAction(getTreeViewer()));
+ saveDefaultSessionAction = new OprofileViewSaveDefaultSessionAction();
+ manager.add(saveDefaultSessionAction);
+ deleteSessionAction = new OprofileViewDeleteSessionAction(getTreeViewer());
+ manager.add(deleteSessionAction);
}
-
+
private TreeViewer getTreeViewer() {
return viewer;
}
-
+
/**
- * Extremely convoluted way of getting the running and parsing to happen in
- * a separate thread, with a progress monitor. In most cases and on fast
+ * Extremely convoluted way of getting the running and parsing to happen in
+ * a separate thread, with a progress monitor. In most cases and on fast
* machines this will probably only be a blip.
*/
public void refreshView() {
@@ -108,7 +118,7 @@ public class OprofileView extends ViewPart {
final UiModelRoot UiRoot = UiModelRoot.getDefault();
UiRoot.refreshModel();
-
+
Display.getDefault().asyncExec(new Runnable() {
public void run() {
OprofileUiPlugin.getDefault().getOprofileView().getTreeViewer().setInput(UiRoot);
@@ -119,7 +129,7 @@ public class OprofileView extends ViewPart {
monitor.done();
}
};
-
+
ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(true, false, refreshRunner);
@@ -130,9 +140,37 @@ public class OprofileView extends ViewPart {
}
}
+ public void selectionChanged(SelectionChangedEvent event) {
+ TreeSelection tsl = (TreeSelection) viewer.getSelection();
+ if (tsl.getFirstElement() instanceof UiModelSession) {
+ if (!deleteSessionAction.isEnabled()) {
+ deleteSessionAction.setEnabled(true);
+ }
+
+ if (((UiModelSession) tsl.getFirstElement()).isDefaultSession()) {
+ if (!saveDefaultSessionAction.isEnabled()) {
+ saveDefaultSessionAction.setEnabled(true);
+ }
+
+ }
+
+ } else {
+ deleteSessionAction.setEnabled(false);
+ saveDefaultSessionAction.setEnabled(false);
+
+ }
+
+ }
+
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
+ @Override
+ public void dispose() {
+ super.dispose();
+ viewer.removeSelectionChangedListener(this);
+ }
+
}
diff --git a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewDeleteSessionAction.java b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewDeleteSessionAction.java
index cee44aa..104e548 100644..100755
--- a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewDeleteSessionAction.java
+++ b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewDeleteSessionAction.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Red Hat - initial API and implementation
*******************************************************************************/
@@ -19,12 +19,13 @@ import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiPlugin;
import org.eclipse.linuxtools.oprofile.ui.model.UiModelSession;
public class OprofileViewDeleteSessionAction extends Action {
-
+
private TreeViewer treeViewer;
public OprofileViewDeleteSessionAction(TreeViewer tree) {
super("Delete Session"); //$NON-NLS-1$
treeViewer = tree;
+ setEnabled(false);
}
@Override
@@ -48,6 +49,8 @@ public class OprofileViewDeleteSessionAction extends Action {
String eventName = sess.getParent().getLabelText();
try {
OprofileCorePlugin.getDefault().getOpcontrolProvider().deleteSession(sessionName, eventName);
+ // clear out collected data by this session
+ OprofileCorePlugin.getDefault().getOpcontrolProvider().reset();
} catch (OpcontrolException e) {
OprofileCorePlugin.showErrorDialog("opcontrolProvider", e); //$NON-NLS-1$
}
diff --git a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewSaveDefaultSessionAction.java b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewSaveDefaultSessionAction.java
index fc2264c..913283c 100644..100755
--- a/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewSaveDefaultSessionAction.java
+++ b/oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/view/OprofileViewSaveDefaultSessionAction.java
@@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
- * Keith Seitz <keiths@redhat.com> - SaveSessionValidator code
- *******************************************************************************/
+ * Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
+ * Keith Seitz <keiths@redhat.com> - SaveSessionValidator code
+ *******************************************************************************/
package org.eclipse.linuxtools.internal.oprofile.ui.view;
import java.text.MessageFormat;
@@ -34,7 +34,7 @@ import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
/**
* Menu item to save the default session. Moved from a double-click in the view
- * on the default session for consistency (since non-default sessions can't be saved).
+ * on the default session for consistency (since non-default sessions can't be saved).
*/
public class OprofileViewSaveDefaultSessionAction extends Action {
private IRemoteFileProxy proxy;
@@ -42,22 +42,26 @@ public class OprofileViewSaveDefaultSessionAction extends Action {
public OprofileViewSaveDefaultSessionAction() {
super(OprofileUiMessages.getString("view.actions.savedefaultsession.label")); //$NON-NLS-1$
}
-
+
@Override
public void run() {
boolean defaultSessionExists = false;
+ String defaultSessionName = null;
+ String eventName = null;
UiModelRoot modelRoot = UiModelRoot.getDefault();
-
+
if (modelRoot.hasChildren()) {
IUiModelElement[] events = modelRoot.getChildren();
for (IUiModelElement e : events) {
if (e instanceof UiModelError)
break;
-
+
IUiModelElement[] sessions = e.getChildren();
for (IUiModelElement s : sessions) {
if (((UiModelSession)s).isDefaultSession()) {
defaultSessionExists = true;
+ defaultSessionName = s.getLabelText();
+ eventName = s.getParent().getLabelText();
break;
}
}
@@ -65,7 +69,7 @@ public class OprofileViewSaveDefaultSessionAction extends Action {
break;
}
}
-
+
if (defaultSessionExists) {
//the following code was originially written by Keith Seitz
InputDialog dialog = new InputDialog(OprofileUiPlugin.getActiveWorkbenchShell(),
@@ -73,11 +77,15 @@ public class OprofileViewSaveDefaultSessionAction extends Action {
OprofileUiMessages.getString("savedialog.message"), //$NON-NLS-1$
OprofileUiMessages.getString("savedialog.initial"), //$NON-NLS-1$
new SaveSessionValidator());
-
+
int result = dialog.open();
if (result == Window.OK) {
try {
OprofileCorePlugin.getDefault().getOpcontrolProvider().saveSession(dialog.getValue());
+ // remove the default session
+ OprofileCorePlugin.getDefault().getOpcontrolProvider().deleteSession(defaultSessionName, eventName);
+ // clear out collected data by this session
+ OprofileCorePlugin.getDefault().getOpcontrolProvider().reset();
OprofileUiPlugin.getDefault().getOprofileView().refreshView();
} catch (OpcontrolException oe) {
OprofileCorePlugin.showErrorDialog("opcontrolProvider", oe); //$NON-NLS-1$
@@ -89,7 +97,7 @@ public class OprofileViewSaveDefaultSessionAction extends Action {
OprofileUiMessages.getString("defaultsessiondialog.nodefaultsession.message")); //$NON-NLS-1$
}
}
-
+
//Original author: Keith Seitz <keiths@redhat.com>
private class SaveSessionValidator implements IInputValidator {
public String isValid(String newText) {
@@ -97,26 +105,26 @@ public class OprofileViewSaveDefaultSessionAction extends Action {
if (newText.length() == 0) {
return ""; //$NON-NLS-1$
}
-
+
// Cannot contain invalid characters
int index = newText.indexOf('/');
if (index == -1) {
index = newText.indexOf('\\');
}
-
+
if (index != -1) {
String format = OprofileUiMessages.getString("savedialog.validator.invalidChar"); //$NON-NLS-1$
Object[] fmtArgs = new Object[] { newText.substring(index, index + 1), newText };
return MessageFormat.format(format, fmtArgs);
}
-
+
// Cannot contain whitespace
if (newText.contains(" ") || newText.contains("\t")) { //$NON-NLS-1$ //$NON-NLS-2$
String format = OprofileUiMessages.getString("savedialog.validator.containsWhitespace"); //$NON-NLS-1$
Object[] fmtArgs = new Object[] { newText };
return MessageFormat.format(format, fmtArgs);
}
-
+
// Must not already exist (opcontrol doesn't allow it)
try {
@@ -136,4 +144,6 @@ public class OprofileViewSaveDefaultSessionAction extends Action {
return null;
}
};
+
+
}