Search in sources :

Example 1 with UiModelRoot

use of org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot in project linuxtools by eclipse.

the class OprofileViewSaveDefaultSessionAction method run.

@Override
public void run() {
    boolean defaultSessionExists = false;
    UiModelRoot modelRoot = UiModelRoot.getDefault();
    String defaultSessionName = null;
    IUiModelElement[] modelEvents = null;
    if (modelRoot.hasChildren()) {
        IUiModelElement[] sessions = modelRoot.getChildren();
        for (IUiModelElement e : sessions) {
            if (e instanceof UiModelError)
                break;
            if (e instanceof UiModelSession) {
                if (((UiModelSession) e).isDefaultSession()) {
                    defaultSessionExists = true;
                    defaultSessionName = e.getLabelText();
                    modelEvents = ((UiModelSession) e).getChildren();
                    break;
                }
                if (defaultSessionExists)
                    break;
            }
        }
        if (defaultSessionExists) {
            // the following code was originially written by Keith Seitz
            InputDialog dialog = new InputDialog(OprofileUiPlugin.getActiveWorkbenchShell(), // $NON-NLS-1$
            OprofileUiMessages.getString("savedialog.title"), // $NON-NLS-1$
            OprofileUiMessages.getString("savedialog.message"), // $NON-NLS-1$
            OprofileUiMessages.getString("savedialog.initial"), new SaveSessionValidator());
            int result = dialog.open();
            if (result == Window.OK) {
                SessionManager.saveSession(dialog.getValue());
                // remove the default session
                for (int i = 0; i < modelEvents.length; i++) {
                    SessionManager.deleteSession(defaultSessionName, modelEvents[i].getLabelText());
                }
                if (Oprofile.OprofileProject.OPERF_BINARY.equals(Oprofile.OprofileProject.getProfilingBinary())) {
                    // remove oprofile_data so current event no longer
                    // be there
                    OprofileViewDeleteSessionAction.deleteOperfDataFolder(Oprofile.OprofileProject.getProject().getFolder(Oprofile.OprofileProject.OPERF_DATA));
                }
                OprofileUiPlugin.getDefault().getOprofileView().refreshView();
            }
        } else {
            MessageDialog.openError(OprofileUiPlugin.getActiveWorkbenchShell(), OprofileUiMessages.getString(// $NON-NLS-1$
            "defaultsessiondialog.nodefaultsession.title"), OprofileUiMessages.getString(// $NON-NLS-1$
            "defaultsessiondialog.nodefaultsession.message"));
        }
    }
}
Also used : UiModelSession(org.eclipse.linuxtools.oprofile.ui.model.UiModelSession) InputDialog(org.eclipse.jface.dialogs.InputDialog) IUiModelElement(org.eclipse.linuxtools.oprofile.ui.model.IUiModelElement) UiModelError(org.eclipse.linuxtools.oprofile.ui.model.UiModelError) UiModelRoot(org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot)

Example 2 with UiModelRoot

use of org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot in project linuxtools by eclipse.

the class OprofileView method refreshView.

/**
 * 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() {
    try {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(OprofileUiPlugin.ID_OPROFILE_VIEW);
    } catch (PartInitException e) {
        e.printStackTrace();
    }
    IRunnableWithProgress refreshRunner = monitor -> {
        // $NON-NLS-1$
        monitor.beginTask(OprofileUiMessages.getString("view.dialog.parsing.text"), 2);
        OpModelRoot dataModelRoot = OpModelRoot.getDefault();
        dataModelRoot.refreshModel();
        monitor.worked(1);
        final UiModelRoot UiRoot = UiModelRoot.getDefault();
        UiRoot.refreshModel();
        Display.getDefault().asyncExec(() -> OprofileUiPlugin.getDefault().getOprofileView().getTreeViewer().setInput(UiRoot));
        monitor.worked(1);
        monitor.done();
    };
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(true, false, refreshRunner);
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) UiModelSession(org.eclipse.linuxtools.oprofile.ui.model.UiModelSession) UiModelRoot(org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot) ViewPart(org.eclipse.ui.part.ViewPart) PlatformUI(org.eclipse.ui.PlatformUI) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) MenuManager(org.eclipse.jface.action.MenuManager) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IAction(org.eclipse.jface.action.IAction) Display(org.eclipse.swt.widgets.Display) InvocationTargetException(java.lang.reflect.InvocationTargetException) OprofileUiPlugin(org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiPlugin) IMenuManager(org.eclipse.jface.action.IMenuManager) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) TreeSelection(org.eclipse.jface.viewers.TreeSelection) OprofileUiMessages(org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiMessages) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) OpModelRoot(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelRoot) OpModelRoot(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelRoot) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) UiModelRoot(org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot)

Aggregations

UiModelRoot (org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot)2 UiModelSession (org.eclipse.linuxtools.oprofile.ui.model.UiModelSession)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IAction (org.eclipse.jface.action.IAction)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 OpModelRoot (org.eclipse.linuxtools.internal.oprofile.core.model.OpModelRoot)1 OprofileUiMessages (org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiMessages)1 OprofileUiPlugin (org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiPlugin)1 IUiModelElement (org.eclipse.linuxtools.oprofile.ui.model.IUiModelElement)1 UiModelError (org.eclipse.linuxtools.oprofile.ui.model.UiModelError)1 SWT (org.eclipse.swt.SWT)1 Composite (org.eclipse.swt.widgets.Composite)1