Search in sources :

Example 11 with BaseExecutor

use of org.eclipse.titan.executor.executors.BaseExecutor in project titan.EclipsePlug-ins by eclipse.

the class ExecutorMonitorView method terminateSelected.

private void terminateSelected() {
    if (null == viewer || viewer.getSelection().isEmpty()) {
        return;
    }
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
        ITreeLeaf element = (ITreeLeaf) iterator.next();
        while (!(element instanceof LaunchElement)) {
            element = element.parent();
        }
        ILaunch launched = ((LaunchElement) element).launch();
        ILaunchConfiguration launchConfiguration = launched.getLaunchConfiguration();
        MainControllerElement mainController;
        if (1 == ((LaunchElement) element).children().size()) {
            mainController = (MainControllerElement) ((LaunchElement) element).children().get(0);
        } else {
            mainController = null;
        }
        if (isSupportedConfiguration(launchConfiguration) && null != mainController) {
            BaseExecutor executor = mainController.executor();
            if (!executor.isTerminated()) {
                executor.terminate(false);
            }
        }
    }
    updateActions();
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) BaseExecutor(org.eclipse.titan.executor.executors.BaseExecutor) ILaunch(org.eclipse.debug.core.ILaunch) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITreeLeaf(org.eclipse.titan.executor.executors.ITreeLeaf)

Example 12 with BaseExecutor

use of org.eclipse.titan.executor.executors.BaseExecutor in project titan.EclipsePlug-ins by eclipse.

the class NotificationView method selectionChanged.

@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
    if (this.equals(part) || !(selection instanceof IStructuredSelection) || null == viewer.getContentProvider()) {
        return;
    }
    ITreeLeaf selectedElement;
    if (selection.isEmpty()) {
        selectedElement = null;
    } else {
        selectedElement = (ITreeLeaf) ((IStructuredSelection) selection).getFirstElement();
    }
    if (null != selectedElement) {
        while (!(selectedElement instanceof LaunchElement)) {
            selectedElement = selectedElement.parent();
        }
    }
    if (null != actualInput && actualInput.equals(selectedElement)) {
        viewer.refresh(false);
    } else {
        viewer.setInput(selectedElement);
        actualInput = selectedElement;
    }
    if (null == selectedElement) {
        setTitleToolTip(null);
        clearAction.setEnabled(false);
        saveAsAction.setEnabled(false);
    } else {
        setTitleToolTip(selectedElement.name());
        clearAction.setEnabled(true);
        saveAsAction.setEnabled(true);
    }
    if (isFollowing && null != actualInput && actualInput instanceof LaunchElement) {
        final List<ITreeLeaf> children = ((LaunchElement) actualInput).children();
        for (ITreeLeaf aChildren : children) {
            final BaseExecutor executor = ((MainControllerElement) aChildren).executor();
            if (null != executor && !executor.notifications().isEmpty()) {
                viewer.reveal(executor.notifications().get(executor.notifications().size() - 1));
            }
        }
    }
}
Also used : BaseExecutor(org.eclipse.titan.executor.executors.BaseExecutor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITreeLeaf(org.eclipse.titan.executor.executors.ITreeLeaf) LaunchElement(org.eclipse.titan.executor.views.executormonitor.LaunchElement) MainControllerElement(org.eclipse.titan.executor.views.executormonitor.MainControllerElement)

Example 13 with BaseExecutor

use of org.eclipse.titan.executor.executors.BaseExecutor in project titan.EclipsePlug-ins by eclipse.

the class NotificationView method saveLaunchElementAs.

/**
 * Saves the contents of a tree starting at the provided launch config node.
 *
 * @param shell the shell to be used to display dialogs.
 * @param actualInput the launch configuration to start from.
 */
public static void saveLaunchElementAs(final Shell shell, final ITreeLeaf actualInput) {
    final FileDialog dialog = new FileDialog(shell, SWT.NONE);
    dialog.setFilterExtensions(new String[] { "log" });
    final String filePath = dialog.open();
    if (null == filePath) {
        return;
    }
    final File file = new File(filePath);
    if (file.exists()) {
        if (!file.canWrite()) {
            ErrorDialog.openError(shell, "Read-only file", "The file is read-only, please choose another file", Status.OK_STATUS);
            return;
        }
    } else {
        try {
            file.createNewFile();
        } catch (IOException e) {
            ErrorDialog.openError(shell, "Can not create file", "The file could not be created and will not be saved", Status.OK_STATUS);
            return;
        }
    }
    if (null == actualInput || !(actualInput instanceof LaunchElement)) {
        // nothing or wrong kind of element selected
        return;
    }
    PrintWriter out = null;
    try {
        out = new PrintWriter(new FileWriter(file));
        final List<ITreeLeaf> children = ((LaunchElement) actualInput).children();
        for (ITreeLeaf aChildren : children) {
            final BaseExecutor executor = ((MainControllerElement) aChildren).executor();
            if (null != executor) {
                List<Notification> tempList = executor.notifications();
                for (Notification aTempList : tempList) {
                    out.println(aTempList.toString());
                }
            }
        }
    } catch (IOException e) {
        ErrorDialog.openError(shell, "Can not write the file", "An error occured while writing to the file\n" + filePath, Status.OK_STATUS);
        return;
    } finally {
        IOUtils.closeQuietly(out);
    }
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IFile[] outputFiles = root.findFilesForLocationURI(URIUtil.toURI(filePath));
    ResourceUtils.refreshResources(Arrays.asList(outputFiles));
}
Also used : IFile(org.eclipse.core.resources.IFile) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) BaseExecutor(org.eclipse.titan.executor.executors.BaseExecutor) ITreeLeaf(org.eclipse.titan.executor.executors.ITreeLeaf) FileDialog(org.eclipse.swt.widgets.FileDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) LaunchElement(org.eclipse.titan.executor.views.executormonitor.LaunchElement) PrintWriter(java.io.PrintWriter) MainControllerElement(org.eclipse.titan.executor.views.executormonitor.MainControllerElement)

Example 14 with BaseExecutor

use of org.eclipse.titan.executor.executors.BaseExecutor in project titan.EclipsePlug-ins by eclipse.

the class JniExecutor method terminate.

@Override
public void terminate(final boolean external) {
    McStateEnum state = jnimw.get_state();
    if (MC_INACTIVE == state.getValue()) {
        setRunning(false);
        isTerminated = true;
        if (mainControllerRoot != null) {
            mainControllerRoot.setTerminated();
            LaunchElement launchElement = null;
            for (Map.Entry<ILaunch, BaseExecutor> entry : ExecutorStorage.getExecutorMap().entrySet()) {
                if (entry.getValue().equals(mainControllerRoot.executor()) && LaunchStorage.getLaunchElementMap().containsKey(entry.getKey())) {
                    launchElement = LaunchStorage.getLaunchElementMap().get(entry.getKey());
                }
            }
            if (launchElement != null) {
                launchElement.setTerminated();
            }
            if (Activator.getMainView() != null) {
                Activator.getMainView().refreshAll();
            }
        }
    } else {
        shutdownSession();
    }
    updateGUI();
}
Also used : BaseExecutor(org.eclipse.titan.executor.executors.BaseExecutor) ILaunch(org.eclipse.debug.core.ILaunch) McStateEnum(org.eclipse.titan.executor.jni.McStateEnum) Map(java.util.Map) HashMap(java.util.HashMap) LaunchElement(org.eclipse.titan.executor.views.executormonitor.LaunchElement)

Example 15 with BaseExecutor

use of org.eclipse.titan.executor.executors.BaseExecutor in project titan.EclipsePlug-ins by eclipse.

the class SingleExecutor method terminate.

@Override
public void terminate(final boolean external) {
    isrunning = false;
    startExecutionAction.setEnabled(false);
    if (mainControllerRoot != null) {
        mainControllerRoot.setTerminated();
        LaunchElement launchElement = null;
        boolean terminatedNaturally = false;
        for (Map.Entry<ILaunch, BaseExecutor> entry : ExecutorStorage.getExecutorMap().entrySet()) {
            if (entry.getValue().equals(mainControllerRoot.executor())) {
                terminatedNaturally = entry.getKey().isTerminated();
                if (LaunchStorage.getLaunchElementMap().containsKey(entry.getKey())) {
                    launchElement = LaunchStorage.getLaunchElementMap().get(entry.getKey());
                }
            }
        }
        if (launchElement != null && !terminatedNaturally && proc != null) {
            proc.destroy();
            try {
                process.terminate();
            } catch (DebugException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
            launchElement.setTerminated();
        }
    }
    if (!keepTemporarilyGeneratedConfigFiles && temporalConfigFile != null) {
        boolean result = temporalConfigFile.delete();
        if (!result) {
            ErrorReporter.logError("The temporal configuration file " + temporalConfigFile.getName() + " could not be deleted");
            return;
        }
    }
    super.shutdownSession();
    temporalConfigFile = null;
    if (Activator.getMainView() != null) {
        Activator.getMainView().refreshAll();
    }
    saveLastTimeUsageInfo();
}
Also used : BaseExecutor(org.eclipse.titan.executor.executors.BaseExecutor) ILaunch(org.eclipse.debug.core.ILaunch) DebugException(org.eclipse.debug.core.DebugException) Map(java.util.Map) LaunchElement(org.eclipse.titan.executor.views.executormonitor.LaunchElement)

Aggregations

BaseExecutor (org.eclipse.titan.executor.executors.BaseExecutor)15 ITreeLeaf (org.eclipse.titan.executor.executors.ITreeLeaf)9 ILaunch (org.eclipse.debug.core.ILaunch)7 LaunchElement (org.eclipse.titan.executor.views.executormonitor.LaunchElement)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)4 MainControllerElement (org.eclipse.titan.executor.views.executormonitor.MainControllerElement)4 List (java.util.List)2 Map (java.util.Map)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 DebugException (org.eclipse.debug.core.DebugException)1 IProcess (org.eclipse.debug.core.model.IProcess)1 Action (org.eclipse.jface.action.Action)1