Search in sources :

Example 1 with UiModelError

use of org.eclipse.linuxtools.oprofile.ui.model.UiModelError 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)

Aggregations

InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IUiModelElement (org.eclipse.linuxtools.oprofile.ui.model.IUiModelElement)1 UiModelError (org.eclipse.linuxtools.oprofile.ui.model.UiModelError)1 UiModelRoot (org.eclipse.linuxtools.oprofile.ui.model.UiModelRoot)1 UiModelSession (org.eclipse.linuxtools.oprofile.ui.model.UiModelSession)1