Example usage for org.eclipse.jface.dialogs MessageDialog openQuestion

List of usage examples for org.eclipse.jface.dialogs MessageDialog openQuestion

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog openQuestion.

Prototype

public static boolean openQuestion(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple Yes/No question dialog.

Usage

From source file:de.uni_koeln.ub.drc.ui.rap.ApplicationWorkbenchAdvisor.java

License:Open Source License

private void login(BundleContext bundleContext) throws Exception {
    String configName = "SIMPLE"; //$NON-NLS-1$
    System.out.println("bundleContext : " //$NON-NLS-1$
            + bundleContext.getClass().getName().toLowerCase());
    URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE);
    loginContext = LoginContextFactory.createContext(configName, configUrl);
    try {//from w ww .  ja v a  2  s  . c  o m
        loginContext.login();
        DrcUiActivator.getDefault().setLoginContext(loginContext);

    } catch (LoginException e) {
        e.printStackTrace();
        boolean retry = MessageDialog.openQuestion(null, Messages.get().Error, Messages.get().LoginFailed);
        if (!retry) {
            redirect();
        } else {
            login(bundleContext);
        }
    }
}

From source file:de.uni_koeln.ub.drc.ui.rcp.Application.java

License:Open Source License

private void login(BundleContext bundleContext) {
    String configName = "SIMPLE"; //$NON-NLS-1$
    System.out.println("bundleContext : " //$NON-NLS-1$
            + bundleContext.getClass().getName().toLowerCase());
    URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE);
    loginContext = LoginContextFactory.createContext(configName, configUrl);
    try {/*from   ww  w  .  ja va  2  s.  co m*/
        loginContext.login();
        SessionContextSingleton.getInstance().setLoginContext(loginContext);
    } catch (LoginException e) {
        e.printStackTrace();
        boolean retry = MessageDialog.openQuestion(null, Messages.get().Error, Messages.get().LoginFailed);
        if (!retry) {
            try {
                DrcUiActivator.getDefault().stop(bundleContext);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            System.exit(0);
        } else {
            login(bundleContext);
        }
    }
}

From source file:de.uni_koeln.ub.drc.ui.rcp.ApplicationWorkbenchAdvisor.java

License:Open Source License

private void login(BundleContext bundleContext) throws Exception {
    String configName = "SIMPLE"; //$NON-NLS-1$
    System.out.println("bundleContext : " + bundleContext.getClass().getName().toLowerCase());
    URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE);
    loginContext = LoginContextFactory.createContext(configName, configUrl);
    try {//  w w w .  j  a v a  2  s.c o m
        loginContext.login();
        DrcUiActivator.getDefault().setLoginContext(loginContext);
    } catch (LoginException e) {
        e.printStackTrace();
        boolean retry = MessageDialog.openQuestion(null, Messages.get().Error, Messages.get().LoginFailed);
        if (!retry) {
            stop(bundleContext);
            System.exit(0);
        } else {
            login(bundleContext);
        }
    }
}

From source file:de.walware.ecommons.emf.ui.forms.EFEditor.java

License:Open Source License

/**
 * Shows a dialog that asks if conflicting changes should be discarded.
 * <!-- begin-user-doc -->//from   w  ww .java  2s . c  o m
 * <!-- end-user-doc -->
 * @generated
 */
protected boolean handleDirtyConflict() {
    return MessageDialog.openQuestion(getSite().getShell(), Messages.EFEditor_FileConflict_title,
            Messages.EFEditor_FileConflict_message);
}

From source file:de.walware.ecommons.ui.util.DNDUtil.java

License:Open Source License

public static boolean setContent(final Clipboard clipboard, final Object[] datas, final Transfer[] tranfers) {
    while (true) {
        try {/*from ww w .  j a  va2  s . c  o  m*/
            clipboard.setContents(datas, tranfers);
            return true;
        } catch (final SWTError e) {
            if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
                throw e;
            }

            if (!MessageDialog.openQuestion(UIAccess.getActiveWorkbenchShell(true),
                    Messages.CopyToClipboard_error_title, Messages.CopyToClipboard_error_message)) {
                return false;
            }
        }
    }
}

From source file:de.walware.statet.base.internal.ui.preferences.CodeGenerationTemplatesConfigurationBlock.java

License:Open Source License

private boolean confirmOverwrite(final File file) {
    return MessageDialog.openQuestion(getShell(), Messages.CodeTemplates_Export_Exists_title,
            NLS.bind(Messages.CodeTemplates_Export_Exists_message, file.getAbsolutePath()));
}

From source file:de.walware.statet.nico.internal.ui.preferences.ResourceMappingPreferencePage.java

License:Open Source License

@Override
public void performDefaults() {
    if (fList.isEmpty()) {
        return;//w  w w  .  j a  v a  2  s  .c o m
    }
    final boolean deleteAll = MessageDialog.openQuestion(getShell(), "Load Defaults", "Delete all mappings?");
    if (deleteAll) {
        fList.clear();
        updateControls();
    }
}

From source file:de.walware.statet.nico.ui.util.ExportConsoleOutputWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    fConfigPage.saveSettings();//from w w w.j av a 2s.c o  m
    final boolean openInEditor = fConfigPage.getOpenInEditor();
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                final SubMonitor progress = SubMonitor.convert(monitor, "Export Output", 100);
                final TextConsoleViewer outputViewer = fConsolePage.getOutputViewer();
                final AbstractDocument document = (AbstractDocument) outputViewer.getDocument();

                final IJobManager jobManager = Job.getJobManager();
                final ISchedulingRule schedulingRule = fConsolePage.getConsole().getSchedulingRule();
                jobManager.beginRule(schedulingRule, progress.newChild(1));
                try {
                    if (fSelectionLength > 0) {
                        final AtomicReference<ITextSelection> currentSelection = new AtomicReference<ITextSelection>();
                        getShell().getDisplay().syncExec(new Runnable() {
                            @Override
                            public void run() {
                                final ITextSelection selection = (ITextSelection) outputViewer.getSelection();
                                if (selection.getLength() != fSelectionLength) {
                                    final boolean continueExport = MessageDialog.openQuestion(getShell(),
                                            "Export Output",
                                            "The selection is changed due to updates in the console. Do you want to continue nevertheless?");
                                    if (!continueExport) {
                                        return;
                                    }
                                }
                                currentSelection.set(selection);
                            }
                        });
                        final ITextSelection selection = currentSelection.get();
                        if (selection == null) {
                            return;
                        }

                        progress.setWorkRemaining(95);
                        export(document, selection.getOffset(), selection.getLength(), openInEditor, progress);
                    } else {
                        progress.setWorkRemaining(95);
                        export(document, 0, document.getLength(), openInEditor, progress);
                    }
                } finally {
                    jobManager.endRule(schedulingRule);
                }
            }
        });
    } catch (final InvocationTargetException e) {
        final Throwable cause = e.getCause();
        StatusManager.getManager()
                .handle(new Status(IStatus.ERROR, NicoUI.PLUGIN_ID, -1,
                        "An error occurred when exporting console output to file.", cause),
                        StatusManager.LOG | StatusManager.SHOW);
        return !(cause instanceof CoreException || cause instanceof IOException);
    } catch (final InterruptedException e) {
    }
    return true;
}

From source file:de.walware.statet.r.internal.console.ui.launching.RRemoteConsoleLaunchDelegate.java

License:Open Source License

private void launchRjsJriRemote(final ILaunchConfiguration configuration, final String mode,
        final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    final IWorkbenchPage page = UIAccess.getActiveWorkbenchPage(false);
    final SubMonitor progress = LaunchConfigUtil.initProgressMonitor(configuration, monitor, 25);

    final long timestamp = System.currentTimeMillis();

    final String type = configuration.getAttribute(RConsoleLaunching.ATTR_TYPE, (String) null).trim();
    final String username = configuration.getAttribute(RConsoleLaunching.ATTR_LOGIN_NAME, (String) null);

    progress.worked(1);/* w  ww . java  2s  .co m*/
    if (progress.isCanceled()) {
        return;
    }

    IREnvConfiguration rEnv = null;
    try {
        rEnv = RLaunching.getREnvConfig(configuration, false);
    } catch (final Exception e) {
    }

    // load tracking configurations
    final List<TrackingConfiguration> trackingConfigs;
    {
        final List<String> trackingIds = configuration.getAttribute(RConsoleOptionsTab.TRACKING_ENABLED_IDS,
                Collections.EMPTY_LIST);
        trackingConfigs = new ArrayList<TrackingConfiguration>(trackingIds.size());
        for (final String id : trackingIds) {
            final TrackingConfiguration trackingConfig;
            if (id.equals(HistoryTrackingConfiguration.HISTORY_TRACKING_ID)) {
                trackingConfig = new HistoryTrackingConfiguration(id);
            } else {
                trackingConfig = new TrackingConfiguration(id);
            }
            RConsoleOptionsTab.TRACKING_UTIL.load(trackingConfig, configuration);
            trackingConfigs.add(trackingConfig);
        }
    }

    progress.worked(1);
    if (progress.isCanceled()) {
        return;
    }

    final Map reconnect = configuration.getAttribute(IRemoteEngineController.LAUNCH_RECONNECT_ATTRIBUTE,
            (Map) null);
    final ToolProcess prevProcess;
    boolean prevProcessDisposeFinally = true;
    if (reconnect != null) {
        prevProcess = (ToolProcess) reconnect.get("process"); //$NON-NLS-1$
    } else {
        prevProcess = null;
    }

    progress.worked(1);
    if (progress.isCanceled()) {
        return;
    }

    try {
        // r env
        //         REnvConfiguration renv = REnvTab.getREnv(configuration);
        //         renv.validate();
        //         
        //         progress.worked(1);
        //         if (monitor.isCanceled()) {
        //            return;
        //         }

        // arguments
        String address;
        if (reconnect != null && reconnect.containsKey("address")) { //$NON-NLS-1$
            address = (String) reconnect.get("address"); //$NON-NLS-1$
        } else {
            address = configuration.getAttribute(RConsoleLaunching.ATTR_ADDRESS, (String) null);
        }
        if (address == null || address.isEmpty()) {
            throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID,
                    ICommonStatusConstants.LAUNCHCONFIG_ERROR,
                    RConsoleMessages.LaunchDelegate_error_MissingAddress_message, null));
        }
        if (!(address.startsWith("//") || address.startsWith("rmi:"))) { //$NON-NLS-1$ //$NON-NLS-2$
            address = "//" + address; //$NON-NLS-1$
        }
        // Working directory
        final FileValidator validator = REnvTab.getWorkingDirectoryValidator(configuration, false);
        final IFileStore workingDirectory = (validator.validate(null).getSeverity() != IStatus.ERROR)
                ? validator.getFileStore()
                : null;
        { // Replace variable in address
            final Matcher matcher = WD_PATTERN.matcher(address);
            if (matcher.find()) {
                if (workingDirectory == null) {
                    throw new CoreException(validator.getStatus());
                }
                address = matcher.replaceAll(workingDirectory.getName());
            }
        }

        final boolean sshTunnel = configuration.getAttribute(RConsoleLaunching.ATTR_SSH_TUNNEL_ENABLED, false);
        final Map<String, Object> loginData = new HashMap<String, Object>();

        RMIAddress rmiAddress = null;
        RMIClientSocketFactory socketFactory = null;
        Session sshSession = null;
        int todo = TODO_START_SERVER;
        Exception todoException = null;
        Registry registry = null;
        boolean registryOK = false;
        try {
            progress.subTask(RConsoleMessages.LaunchDelegate_CheckingRegistry_subtask);
            rmiAddress = new RMIAddress(address);

            // init login data
            loginData.put(LOGIN_USERNAME_DATA_KEY, username);
            if (type.equals(RConsoleLaunching.REMOTE_RJS_SSH)) {
                loginData.put(LOGIN_USERNAME_FORCE_DATA_KEY, true);
            }
            final int sshPort = configuration.getAttribute(RConsoleLaunching.ATTR_SSH_PORT, DEFAULT_SSH_PORT);
            loginData.put(LOGIN_SSH_HOST_DATA_KEY, rmiAddress.getHostAddress().getHostAddress());
            loginData.put(LOGIN_SSH_PORT_DATA_KEY, Integer.valueOf(sshPort));

            final Remote remote;
            if (sshTunnel) {
                if (sshSession == null) {
                    sshSession = RjsUtil.getSession(loginData, progress.newChild(5));
                }

                socketFactory = RjsUtil.createRMIOverSshClientSocketFactory(sshSession);
                RjsComConfig.setRMIClientSocketFactory(socketFactory);
                registry = LocateRegistry.getRegistry("127.0.0.1", rmiAddress.getPortNum(), //$NON-NLS-1$
                        socketFactory);
                remote = registry.lookup(rmiAddress.getName());
                registryOK = true;
            } else {
                RMIUtil.checkRegistryAccess(rmiAddress);
                RjsComConfig.setRMIClientSocketFactory(null);
                registry = LocateRegistry.getRegistry(rmiAddress.getHost(), rmiAddress.getPortNum(),
                        socketFactory);
                remote = registry.lookup(rmiAddress.getName());
                registryOK = true;
            }
            if (remote instanceof Server) {
                final Server server = (Server) remote;
                final int state = server.getState();
                if (state <= Server.S_NOT_STARTED) {
                    todo = TODO_START_R;
                    if (reconnect != null) {
                        throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID, 0, NLS
                                .bind("Cannot reconnect, the R engine at ''{0}'' is not yet started.", address),
                                null));
                    }
                } else if (state == Server.S_CONNECTED) {
                    todo = TODO_CONNECT;
                    if (reconnect != null) {
                    } else {
                        final Shell shell = page.getWorkbenchWindow().getShell();
                        final Display display = UIAccess.getDisplay(shell);
                        final String msg = NLS.bind(
                                "It seems, a client is already connected to the remote R engine (''{0}'').\n Do you want to disconnect this client and connect to the engine?",
                                address);
                        final AtomicBoolean force = new AtomicBoolean(false);
                        display.syncExec(new Runnable() {
                            @Override
                            public void run() {
                                force.set(MessageDialog.openQuestion(shell, "Connect", msg));
                            }
                        });
                        if (!force.get()) {
                            monitor.setCanceled(true);
                            throw new CoreException(Status.CANCEL_STATUS);
                        }
                    }
                } else if (state <= Server.S_LOST) {
                    todo = TODO_CONNECT;
                } else if (state == Server.S_STOPPED) {
                    if (reconnect != null) {
                        throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID, 0,
                                NLS.bind("Cannot reconnect, the R engine at ''{0}'' is terminated.", address),
                                null));
                    }
                    todo = TODO_START_SERVER;
                } else {
                    throw new IllegalStateException("Server state: " + state);
                }
            }
        } catch (final UnknownHostException e) {
            throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID,
                    ICommonStatusConstants.LAUNCHCONFIG_ERROR,
                    RConsoleMessages.LaunchDelegate_error_InvalidAddress_message, e));
        } catch (final MalformedURLException e) {
            throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID,
                    ICommonStatusConstants.LAUNCHCONFIG_ERROR,
                    RConsoleMessages.LaunchDelegate_error_InvalidAddress_message, e));
        } catch (final RemoteException e) {
            if (!registryOK) {
                registry = null;
            }
            todoException = e;
            todo = TODO_START_SERVER;
        } catch (final NotBoundException e) {
            todoException = e;
            todo = TODO_START_SERVER;
        }

        progress.worked(5);
        if (progress.isCanceled()) {
            return;
        }

        final String[] args = LaunchConfigUtil.getProcessArguments(configuration,
                RConsoleLaunching.ATTR_OPTIONS);

        if (reconnect != null) {
            final Map<String, String> reconnectData = (Map<String, String>) reconnect.get("initData"); //$NON-NLS-1$
            if (reconnectData != null) {
                loginData.putAll(reconnectData);
            }
        }

        String command = null;
        if (todo == TODO_START_SERVER) {
            progress.subTask(RConsoleMessages.LaunchDelegate_StartREngine_subtask);
            progress.setWorkRemaining(21);
            if (type.equals(RConsoleLaunching.REMOTE_RJS_SSH)) {
                command = configuration.getAttribute(RConsoleLaunching.ATTR_COMMAND, ""); //$NON-NLS-1$
                if (command.isEmpty()) {
                    throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID,
                            ICommonStatusConstants.LAUNCHCONFIG_ERROR,
                            "Command to startup R over SSH is missing.", null)); //$NON-NLS-1$
                }

                final Matcher addressMatcher = ADDRESS_PATTERN.matcher(command);
                if (addressMatcher.find()) {
                    command = addressMatcher.replaceAll(rmiAddress.getAddress());
                }

                final Matcher nameMatcher = NAME_PATTERN.matcher(command);
                if (nameMatcher.find()) {
                    command = nameMatcher.replaceAll(rmiAddress.getName());
                }

                final Matcher wdMatcher = WD_PATTERN.matcher(command);
                if (wdMatcher.find()) {
                    if (workingDirectory == null) {
                        throw new CoreException(validator.getStatus());
                    }
                    final IResourceMappingManager rmManager = ResourceMappingUtils.getManager();
                    final IPath path = (rmManager != null) ? rmManager.mapFileStoreToRemoteResource(
                            rmiAddress.getHostAddress().getHostAddress(), workingDirectory) : null;
                    if (path == null) {
                        throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID,
                                NLS.bind("Cannot resolve working directory ''{0}'' to remote path.",
                                        workingDirectory.toString())));
                    }
                    command = wdMatcher.replaceAll(path.toString());
                }

                final Hashtable<String, String> envp = new Hashtable<String, String>();
                envp.put("LC_ALL", "C"); //$NON-NLS-1$ //$NON-NLS-2$
                envp.put("LANG", "C"); //$NON-NLS-1$ //$NON-NLS-2$
                envp.put("LC_NUMERIC", "C"); //$NON-NLS-1$ //$NON-NLS-2$
                RjsUtil.startRemoteServerOverSsh(RjsUtil.getSession(loginData, progress.newChild(5)), command,
                        envp, progress.newChild(5));

                progress.subTask(RConsoleMessages.LaunchDelegate_WaitForR_subtask);
                final long t = System.nanoTime();
                WAIT: for (int i = 0; true; i++) {
                    if (progress.isCanceled()) {
                        throw new CoreException(Status.CANCEL_STATUS);
                    }
                    try {
                        if (registry == null) {
                            if (sshTunnel) {
                                if (sshSession == null) {
                                    sshSession = RjsUtil.getSession(loginData, progress.newChild(5));
                                }
                                if (socketFactory == null) {
                                    socketFactory = RjsUtil.createRMIOverSshClientSocketFactory(sshSession);
                                }
                                registry = LocateRegistry.getRegistry("127.0.0.1", rmiAddress.getPortNum(), //$NON-NLS-1$
                                        socketFactory);
                            } else {
                                RMIUtil.checkRegistryAccess(rmiAddress);
                                registryOK = true;
                                registry = LocateRegistry.getRegistry(rmiAddress.getHost(),
                                        rmiAddress.getPortNum());
                            }
                        }
                        final String[] list = registry.list();
                        registryOK = true;
                        for (final String entry : list) {
                            if (entry.equals(rmiAddress.getName())) {
                                break WAIT;
                            }
                        }
                        if (i > 1 && System.nanoTime() - t > TIMEOUT) {
                            break WAIT;
                        }
                    } catch (final RemoteException e) {
                        if (i > 0 && System.nanoTime() - t > TIMEOUT / 3) {
                            if (registry == null) {
                                RjsController.lookup(null, e, rmiAddress);
                            }
                            break WAIT;
                        }
                        if (!registryOK) {
                            registry = null;
                        }
                    }
                    try {
                        Thread.sleep(333);
                    } catch (final InterruptedException e) {
                        // continue, monitor is checked
                    }
                }
                progress.worked(5);

                todo = TODO_START_R;
            } else {
                if (reconnect != null) {
                    throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID, 0, NLS
                            .bind("Cannot reconnect to server, no R engine is available at ''{0}''.", address),
                            todoException));
                } else {
                    throw new CoreException(new Status(IStatus.ERROR, RConsoleUIPlugin.PLUGIN_ID, 0, NLS.bind(
                            "Cannot start or reconnect to server, to R engine at ''{0}''. You have to restart the server (manually or using SSH automation).",
                            address), todoException));
                }
            }
        }

        final RjsConnection connection = RjsController.lookup(registry, null, rmiAddress);

        // create process
        UnterminatedLaunchAlerter.registerLaunchType(RConsoleLaunching.R_REMOTE_CONSOLE_CONFIGURATION_TYPE_ID);
        final boolean startup = (todo == TODO_START_R);

        final RProcess process = new RProcess(launch, rEnv, LaunchConfigUtil.createLaunchPrefix(configuration),
                ((rEnv != null) ? rEnv.getName() : "-") + " / RJ " + rmiAddress.toString() + ' ' //$NON-NLS-1$//$NON-NLS-2$
                        + LaunchConfigUtil.createProcessTimestamp(timestamp), rmiAddress.toString(), (workingDirectory != null) ? workingDirectory.toString() : null,
                timestamp);
        process.setAttribute(IProcess.ATTR_CMDLINE,
                rmiAddress.toString() + '\n' + ((startup) ? Arrays.toString(args) : "rjs-reconnect")); //$NON-NLS-1$

        final HashMap<String, Object> rjsProperties = new HashMap<String, Object>();
        rjsProperties.put(RjsComConfig.RJ_DATA_STRUCTS_LISTS_MAX_LENGTH_PROPERTY_ID,
                configuration.getAttribute(RConsoleLaunching.ATTR_OBJECTDB_LISTS_MAX_LENGTH, 10000));
        rjsProperties.put(RjsComConfig.RJ_DATA_STRUCTS_ENVS_MAX_LENGTH_PROPERTY_ID,
                configuration.getAttribute(RConsoleLaunching.ATTR_OBJECTDB_ENVS_MAX_LENGTH, 10000));
        rjsProperties.put("rj.session.startup.time", timestamp); //$NON-NLS-1$
        final RjsController controller = new RjsController(process, rmiAddress, connection, loginData, false,
                startup, args, rjsProperties, null,
                RConsoleRJLaunchDelegate.createWorkspaceConfig(configuration), trackingConfigs);

        // move all tasks, if started
        if (reconnect != null && prevProcess != null) {
            controller.addToolStatusListener(new IToolStatusListener() {
                @Override
                public void controllerStatusRequested(final ToolStatus currentStatus,
                        final ToolStatus requestedStatus, final List<DebugEvent> eventCollection) {
                }

                @Override
                public void controllerStatusRequestCanceled(final ToolStatus currentStatus,
                        final ToolStatus requestedStatus, final List<DebugEvent> eventCollection) {
                }

                @Override
                public void controllerStatusChanged(final ToolStatus oldStatus, final ToolStatus newStatus,
                        final List<DebugEvent> eventCollection) {
                    if (newStatus != ToolStatus.TERMINATED) {
                        final Queue prevQueue = prevProcess.getQueue();
                        prevQueue.moveAll(process.getQueue());
                    }
                    prevProcess.restartCompleted(reconnect);
                    controller.removeToolStatusListener(this);
                }
            });
        }
        process.init(controller);

        RConsoleLaunching.registerDefaultHandlerTo(controller);
        controller.addCommandHandler(IToolEventHandler.LOGIN_REQUEST_EVENT_ID, new LoginHandler());

        progress.worked(5);

        RConsoleRJLaunchDelegate.initConsoleOptions(controller, rEnv, configuration, startup);

        if (fAddon != null) {
            fAddon.init(configuration, mode, controller, monitor);
        }

        final RConsole console = new RConsole(process, new NIConsoleColorAdapter());
        NicoUITools.startConsoleLazy(console, page,
                configuration.getAttribute(RConsoleLaunching.ATTR_PIN_CONSOLE, false));
        // start
        new ToolRunner().runInBackgroundThread(process, new WorkbenchStatusHandler());
        prevProcessDisposeFinally = false;
    } finally {
        RjsComConfig.clearRMIClientSocketFactory();
        if (prevProcessDisposeFinally && reconnect != null && prevProcess != null) {
            prevProcess.restartCompleted(reconnect);
        }
    }
}

From source file:descent.internal.ui.actions.CopyQualifiedNameAction.java

License:Open Source License

public void run() {

    try {//from ww  w. j av a2 s  .  co  m
        IJavaElement[] elements = getSelectedElements();
        if (elements == null) {
            MessageDialog.openInformation(getShell(), ActionMessages.CopyQualifiedNameAction_InfoDialogTitel,
                    ActionMessages.CopyQualifiedNameAction_NoElementToQualify);
            return;
        }

        Object[] data = null;
        Transfer[] dataTypes = null;

        if (elements.length == 1) {
            String qualifiedName = JavaElementLabels.getElementLabel(elements[0], LABEL_FLAGS);
            IResource resource = elements[0].getCorrespondingResource();

            if (resource != null) {
                IPath location = resource.getLocation();
                if (location != null) {
                    data = new Object[] { qualifiedName, resource, new String[] { location.toOSString() } };
                    dataTypes = new Transfer[] { TextTransfer.getInstance(), ResourceTransfer.getInstance(),
                            FileTransfer.getInstance() };
                } else {
                    data = new Object[] { qualifiedName, resource };
                    dataTypes = new Transfer[] { TextTransfer.getInstance(), ResourceTransfer.getInstance() };
                }
            } else {
                data = new Object[] { qualifiedName };
                dataTypes = new Transfer[] { TextTransfer.getInstance() };
            }
        } else {
            StringBuffer buf = new StringBuffer();
            buf.append(JavaElementLabels.getElementLabel(elements[0], LABEL_FLAGS));
            for (int i = 1; i < elements.length; i++) {
                IJavaElement element = elements[i];

                String qualifiedName = JavaElementLabels.getElementLabel(element, LABEL_FLAGS);
                buf.append('\r').append('\n').append(qualifiedName);
            }
            data = new Object[] { buf.toString() };
            dataTypes = new Transfer[] { TextTransfer.getInstance() };
        }

        try {
            fClipboard.setContents(data, dataTypes);

            // update the enablement of the paste action
            // workaround since the clipboard does not support callbacks            
            if (fPasteAction != null) {
                if (fPasteAction instanceof SelectionDispatchAction) {
                    if (((SelectionDispatchAction) fPasteAction).getSelection() != null) {
                        ((SelectionDispatchAction) fPasteAction)
                                .update(((SelectionDispatchAction) fPasteAction).getSelection());
                    }
                } else if (fPasteAction instanceof IUpdate) {
                    ((IUpdate) fPasteAction).update();
                }
            }
        } catch (SWTError e) {
            if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
                throw e;
            }
            if (MessageDialog.openQuestion(getShell(), ActionMessages.CopyQualifiedNameAction_ErrorTitle,
                    ActionMessages.CopyQualifiedNameAction_ErrorDescription)) {
                fClipboard.setContents(data, dataTypes);
            }
        }
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
    }
}