Example usage for javax.swing SwingUtilities invokeAndWait

List of usage examples for javax.swing SwingUtilities invokeAndWait

Introduction

In this page you can find the example usage for javax.swing SwingUtilities invokeAndWait.

Prototype

public static void invokeAndWait(final Runnable doRun) throws InterruptedException, InvocationTargetException 

Source Link

Document

Causes doRun.run() to be executed synchronously on the AWT event dispatching thread.

Usage

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

/**
 * Set the columns in the ReportQueryDialog....
 * This is called from a none swing thread, hence all the invoke and
 * wait magic./*  w  w  w . j  ava  2 s  . com*/
 * The message is only set if the query string matches the one the 
 * error message is for.
 *
 * @param columns The list of columns to set.
 */
protected void setColumnsFromWorker(final List columns) {
    try {

        Runnable r = new Runnable() {
            public void run() {
                getReportQueryDialog().setColumns(columns);
                getReportQueryDialog().getQueryEditorPane().requestFocusInWindow();
            }
        };

        if (SwingUtilities.isEventDispatchThread()) {
            r.run();
        } else {
            SwingUtilities.invokeAndWait(r);
        }

    } catch (Exception e) {
        // oh well we got interrupted.
    }
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

/**
 * Set the bean explorer// w ww .  jav a  2s . c om
 *
 * @param columns The list of columns to set.
 */
protected void setBeanExplorerFromWorker(final Vector v, final boolean pathOnDescription,
        final boolean useCombo) {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                Vector v1 = v;
                if (v1 == null)
                    v1 = new Vector();

                setComboVisible(useCombo);
                setPathOnDescription(pathOnDescription);
                setClassNames(v1);

                getReportQueryDialog().getQueryEditorPane().requestFocusInWindow();
                getReportQueryDialog().getQueryEditorPane().requestFocus();
            }
        });
    } catch (Exception e) {
        // oh well we got interrupted.
        e.printStackTrace();
    }
}

From source file:com.sshtools.sshvnc.SshVNCPanel.java

public void authenticationComplete(boolean newProfile) throws SshException,

        IOException {//from w  w w .ja  v  a 2s .c om

    statusBar.setStatusText("User authenticated");
    setContainerTitle(getCurrentConnectionProfile().getHost());

    int localPort = 0;

    String host = getCurrentConnectionProfile().getApplicationProperty(PROFILE_PROPERTY_VNC_HOST, "localhost");
    String port = getCurrentConnectionProfile().getApplicationProperty(PROFILE_PROPERTY_VNC_DISPLAY, "5900");

    final VNCDisplay display = new VNCDisplay(host + ":" + port, 5900);

    final String addr = "0.0.0.0";

    String command = getCurrentConnectionProfile().getApplicationProperty(

            PROFILE_PRE_VNC_COMMAND, null);

    if (command != null && command.trim().length() > 0) {

        statusBar.setStatusText("Executing command: " + command);
        remove(vnc);
        add(terminal, BorderLayout.CENTER);

        emulation.reset();
        emulation.clearScreen();
        emulation.setCursorPosition(0, 0);
        terminal.refresh();

        log.debug("Executing pre VNC command" + command);

        SessionChannelClient session = ssh.openSessionChannel();

        session.requestPseudoTerminal("vt100", 80, 24, 0, 0, "");

        if (session.executeCommand(command)) {

            session.bindInputStream(emulation.getTerminalInputStream());
            session.bindOutputStream(emulation.getTerminalOutputStream());
        }

        try {

            session.getState().waitForState(ChannelState.CHANNEL_CLOSED);

        }

        catch (InterruptedException ex) {

        } finally {

            remove(terminal);
            add(vnc, BorderLayout.CENTER);

        }

    }

    statusBar.setStatusText("Setting up VNC forwarding");

    if (log.isDebugEnabled()) {

        log.debug("Setting up forwarding on " + addr

                + " (" + localPort + ") to " + display.getHost()

                + ":" + display.getPort());

    }

    final SshVNCOptions options =

            new SshVNCOptions(getCurrentConnectionProfile());

    statusBar.setStatusText("Initialising VNC");

    ForwardingConfiguration config =

            new ForwardingConfiguration(

                    "VNC",

                    "forwarded-channel",

                    0,

                    display.getHost(),

                    display.getPort());

    channel =

            new ForwardingIOChannel(

                    ForwardingIOChannel.LOCAL_FORWARDING_CHANNEL,

                    "VNC",

                    config.getHostToConnect(),

                    config.getPortToConnect(),

                    addr,

                    display.getPort());

    if (ssh.openChannel(channel)) {

        // The forwarding channel is open so forward to the
        // VNC protocol

        channel.addEventListener(new DataNotificationListener(statusBar));

        if (newProfile) {

            setNeedSave(true);

        }

        new SshThread(new Runnable() {

            public void run() {

                initVNC(

                        channel.getInputStream(),

                        channel.getOutputStream(),

                        options);

            }

        }

                , "VNC", true).start();

    }

    else {

        // We need to close the connection and inform the user

        // that the forwarding failed to start

        try {

            SwingUtilities.invokeAndWait(new Runnable() {

                public void run() {

                    JOptionPane.showMessageDialog(

                            SshVNCPanel.this,

                            "SSHVnc failed to open a forwarding channel to "

                                    + display.toString(),

                            "SSHVnc",

                            JOptionPane.OK_OPTION);

                }

            });

        }

        catch (Exception ex) {

            statusBar.setStatusText(

                    "Could not connect to local forwarding server");

        }

        finally {

            closeConnection(true);

        }

    }

}

From source file:com.sshtools.appframework.ui.SshToolsApplication.java

public void init(String[] args) throws SshToolsApplicationException {
    instance = this;

    boolean listen = isReuseCapable();

    // Do parse 1 of the command line arguments - see if we need to start
    // the daemon
    Options options1 = new Options();
    SshToolsApplication.this.buildCLIOptions(options1);

    pluginManager = new PluginManager();
    try {/*www.j a v  a2 s  .c  om*/
        initPluginManager(options1);
    } catch (PluginException e1) {
        log(PluginHostContext.LOG_ERROR, "Failed to initialise plugin manager.", e1);
    }

    CommandLineParser parser1 = new PosixParser();
    CommandLine commandLine1;

    try {
        // parse the command line arguments
        commandLine1 = parser1.parse(options1, args);
        if (commandLine1.hasOption("d")) {
            listen = false;
        }

        if (commandLine1.hasOption('r')) {
            reusePort = Integer.parseInt(commandLine1.getOptionValue('r'));
        }
    } catch (Exception e) {
        // Don't care at the moment
    }

    // Try and message the reuse daemon if possible - saves starting another
    // instance
    if (listen) {
        Socket s = null;
        try {
            String hostname = "localhost";
            if (reusePort == -1) {
                reusePort = getDefaultReusePort();
            }
            log.debug("Attempting connection to reuse server on " + hostname + ":" + reusePort);
            s = new Socket(hostname, reusePort);
            log.debug("Found reuse server on " + hostname + ":" + reusePort + ", sending arguments");
            s.setSoTimeout(5000);
            PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
            for (int i = 0; args != null && i < args.length; i++) {
                pw.println(args[i]);
            }
            pw.println();
            BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
            log.debug("Waiting for reuse server reply");
            String error = r.readLine();
            log.debug("Reuse server replied with '" + error + "'");
            if (error != null && !error.equals("")) {
                throw new SshToolsApplicationException(error);
            }
            System.exit(0);
        } catch (SshToolsApplicationException t) {
            throw t;
        } catch (SocketException se) {
            log.debug("No reuse server found.");
        } catch (SocketTimeoutException se) {
            log.debug("Reuse server not responding.", se);
        } catch (Exception e) {
            throw new SshToolsApplicationException(e);
        } finally {
            if (s != null) {
                try {
                    s.close();
                } catch (IOException ioe) {
                }
            }
        }
    }

    additionalOptionsTabs = new ArrayList<OptionsTab>();
    log.info("Initialising application");
    File f = getApplicationPreferencesDirectory();
    if (f != null) {
        //
        FilePreferencesFactory.setPreferencesFile(new File(f, "javaprefs.properties"));
        PreferencesStore.init(new File(f, getApplicationName() + ".properties"));
    }
    setLookAndFeel(getDefaultLAF());

    log.debug("Plugin manager initialised, adding global preferences tabs");

    postInitialization();
    addAdditionalOptionsTab(new GlobalOptionsTab(this));

    Options options = new Options();
    buildCLIOptions(options);
    log.debug("Parsing command line");
    CommandLineParser parser = new PosixParser();
    try {
        // parse the command line arguments
        cli = parser.parse(options, args);
        if (cli.hasOption("?")) {
            printHelp(options);
            System.exit(0);
        }
    } catch (Exception e) {
        System.err.println("Invalid option: " + e.getMessage());
        printHelp(options);
        System.exit(1);
    }
    log.debug("Parsed command line");

    if (listen) {
        Thread t = new Thread("RemoteCommandLine") {
            @Override
            public void run() {
                Socket s = null;
                try {
                    reuseServerSocket = new ServerSocket(reusePort, 1);
                    while (true) {
                        s = reuseServerSocket.accept();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
                        String line = null;
                        List<String> args = new ArrayList<String>();
                        while ((line = reader.readLine()) != null && !line.equals("")) {
                            args.add(line);
                        }
                        final PrintWriter pw = new PrintWriter(s.getOutputStream());
                        String[] a = new String[args.size()];
                        args.toArray(a);
                        CommandLineParser parser = new PosixParser();
                        Options options = new Options();
                        buildCLIOptions(options);
                        // parse the command line arguments
                        final CommandLine remoteCLI = parser.parse(options, a);
                        pw.println("");
                        SwingUtilities.invokeAndWait(new Runnable() {
                            public void run() {
                                try {
                                    reuseRequest(remoteCLI);
                                } catch (Throwable t) {
                                    pw.println(t.getMessage());
                                }
                            }
                        });
                        s.close();
                        s = null;
                    }
                } catch (Exception e) {
                    /* DEBUG */e.printStackTrace();
                } finally {
                    if (s != null) {
                        try {
                            s.close();
                        } catch (IOException ioe) {

                        }
                    }
                }
            }
        };
        t.setDaemon(true);
        t.start();
    }
}

From source file:de.codesourcery.eve.skills.market.impl.EveCentralMarketDataProvider.java

private static Map<InventoryType, PriceInfoQueryResult> runOnEventThread(final PriceCallable r)
        throws PriceInfoUnavailableException {
    if (SwingUtilities.isEventDispatchThread()) {
        return r.call();
    }//from w w w.j ava 2s  . co m

    final AtomicReference<Map<InventoryType, PriceInfoQueryResult>> result = new AtomicReference<Map<InventoryType, PriceInfoQueryResult>>();
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                try {
                    result.set(r.call());
                } catch (PriceInfoUnavailableException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (InvocationTargetException e) {
        Throwable wrapped = e.getTargetException();
        if (wrapped instanceof RuntimeException) {
            if (wrapped.getCause() instanceof PriceInfoUnavailableException) {
                throw (PriceInfoUnavailableException) wrapped.getCause();
            }
            throw (RuntimeException) wrapped;
        } else if (e.getTargetException() instanceof Error) {
            throw (Error) wrapped;
        }
        throw new RuntimeException(e.getTargetException());
    }
    return result.get();
}

From source file:com.sshtools.powervnc.PowerVNCPanel.java

public void authenticationComplete(boolean newProfile) throws SshException,

        IOException {//  w  w w.j  a v a 2 s. c om

    //     System.out.println("giga");
    statusBar.setStatusText("User authenticated");
    setContainerTitle(getCurrentConnectionProfile().getHost());

    int localPort = 0;

    String host = getCurrentConnectionProfile().getApplicationProperty(PROFILE_PROPERTY_VNC_HOST, "localhost");
    /*
        String port = getCurrentConnectionProfile()
            .getApplicationProperty(
            PROFILE_PROPERTY_VNC_DISPLAY,
            "5900");
    */
    //    String host = "192.168.0.3";
    String port = PowerVNC.DISPLAY;

    final VNCDisplay display = new VNCDisplay(host + ":" + port, 5900);

    final String addr = "0.0.0.0";

    String command = getCurrentConnectionProfile().getApplicationProperty(

            PROFILE_PRE_VNC_COMMAND, null);

    if (command != null && command.trim().length() > 0) {

        statusBar.setStatusText("Executing command: " + command);
        remove(vnc);
        add(terminal, BorderLayout.CENTER);

        emulation.reset();
        emulation.clearScreen();
        emulation.setCursorPosition(0, 0);
        terminal.refresh();

        log.debug("Executing pre VNC command" + command);

        SessionChannelClient session = ssh.openSessionChannel();

        session.requestPseudoTerminal("vt100", 80, 24, 0, 0, "");

        if (session.executeCommand(command)) {

            session.bindInputStream(emulation.getTerminalInputStream());
            session.bindOutputStream(emulation.getTerminalOutputStream());
        }

        try {

            session.getState().waitForState(ChannelState.CHANNEL_CLOSED);

        }

        catch (InterruptedException ex) {

        } finally {

            remove(terminal);
            //        Rectangle r = new Rectangle(vnc.getWidth(), vnc.getHeight());
            ////        vnc.getSize().
            //        setFrameResizeable(true);
            //        setBounds(r);
            //        refresh();
            add(vnc, BorderLayout.CENTER);
            //        JFrame desktop = new JFrame();
            //        desktop.add(vnc, BorderLayout.CENTER);
            //        desktop.pack();
            //              pack();
        }

    }

    statusBar.setStatusText("Setting up VNC forwarding");

    if (log.isDebugEnabled()) {

        log.debug("Setting up forwarding on " + addr

                + " (" + localPort + ") to " + display.getHost()

                + ":" + display.getPort());

    }

    final PowerVNCOptions options =

            new PowerVNCOptions(getCurrentConnectionProfile());

    statusBar.setStatusText("Initialising VNC");

    ForwardingConfiguration config =

            new ForwardingConfiguration(

                    "VNC",

                    "forwarded-channel",

                    0,

                    display.getHost(),

                    display.getPort());

    channel =

            new ForwardingIOChannel(

                    ForwardingIOChannel.LOCAL_FORWARDING_CHANNEL,

                    "VNC",

                    config.getHostToConnect(),

                    config.getPortToConnect(),

                    addr,

                    display.getPort());

    if (ssh.openChannel(channel)) {

        // The forwarding channel is open so forward to the
        // VNC protocol

        channel.addEventListener(new DataNotificationListener(statusBar));

        if (newProfile) {

            setNeedSave(true);

        }

        new SshThread(new Runnable() {

            public void run() {

                //           setBounds(new Rectangle(1000, 1000));
                //           setVisible(true);
                //           setPreferredSize(new Dimension(1000, 1000));
                //           revalidate();
                //           pack();
                //           this.setsize(new Dimension(1000, 1000));
                initVNC(

                        channel.getInputStream(),

                        channel.getOutputStream(),

                        options);

            }

        }

                , "VNC", true).start();
        //      setBounds(new Rectangle(1000, 1000));
        setSize(800, 800);
        //      show();
        //      setSize(new Dimension(1000, 1000));
        //      revalidate();
        //      resize(800, 800);
        //      refresh();
    }

    else {

        // We need to close the connection and inform the user

        // that the forwarding failed to start

        try {

            SwingUtilities.invokeAndWait(new Runnable() {

                public void run() {

                    JOptionPane.showMessageDialog(

                            PowerVNCPanel.this,

                            "Powua failed to open a forwarding channel to "

                                    + display.toString(),

                            "Powua",

                            JOptionPane.OK_OPTION);

                }

            });

        }

        catch (Exception ex) {

            statusBar.setStatusText(

                    "Could not connect to local forwarding server");

        }

        finally {

            closeConnection(true);

        }

    }

}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

/**
 * Refresh the content of the JComponents
 *//*from  w ww . ja va  2s. c  o  m*/
public void refresh(final Object param) {
    if (refreshAbortable) {
        ProcessMsgBlocker.instance().showMessage("Procesando ...");
        //            final ProcessMsgBlocker msgBlocker = ProcessMsgBlocker.instance();
        //            final SearchMsgBlocker msgBlocker = SearchMsgBlocker.instance();
        SwingWorker swingWorker = new SwingWorker() {
            protected Object doInBackground() throws Exception {
                refreshInternal(param);
                return null;
            }

            protected void done() {
                //                    msgBlocker.close();
                ProcessMsgBlocker.instance().removeMessage();
            }
        };
        swingWorker.execute();
        if (SwingUtilities.isEventDispatchThread()) {
            //                msgBlocker.show();
            ProcessMsgBlocker.instance().showMessage("Procesando ...");
        } else {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        ProcessMsgBlocker.instance().showMessage("Procesando ...");
                        //                            msgBlocker.show();
                    }
                });
            } catch (Throwable e) {
                throw new AWSystemException("Problems refreshing the table:" + this, e);
            }
        }
    } else {
        if (SwingUtilities.isEventDispatchThread()) {
            refreshInternal(param);
        } else {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        refreshInternal(param);
                    }
                });
            } catch (Throwable e) {
                throw new AWSystemException("Problems refreshing the table:" + this, e);
            }
        }
    }
}

From source file:de.cebitec.readXplorer.differentialExpression.plot.BaySeqGraphicsTopComponent.java

@Override
public void update(Object args) {
    if (args instanceof ChartExporter.ChartExportStatus) {
        final ChartExporter.ChartExportStatus status = (ChartExporter.ChartExportStatus) args;
        try {/*from   w  w  w.jav  a2 s. c om*/
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    switch (status) {
                    case RUNNING:
                        saveButton.setEnabled(false);
                        svgExportProgressHandle.start();
                        svgExportProgressHandle.switchToIndeterminate();
                        break;
                    case FAILED:
                        messages.setText("The export of the plot failed.");
                    case FINISHED:
                        messages.setText("SVG image saved.");
                        svgExportProgressHandle.switchToDeterminate(100);
                        svgExportProgressHandle.finish();
                        break;
                    }
                }
            });
        } catch (InterruptedException | InvocationTargetException ex) {
            Date currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
            Logger.getLogger(this.getClass().getName()).log(Level.WARNING, ex.getMessage(), currentTimestamp);
        }
    } else {
        addResults();
    }
}

From source file:be.agiv.security.demo.Main.java

private void invokeClaimsAwareService() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    JPanel contentPanel = new JPanel(gridBagLayout);

    final JLabel ipStsLabel = new JLabel("IP-STS:");
    gridBagConstraints.gridx = 0;/*from  ww w .  j ava2 s .c om*/
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.ipadx = 5;
    gridBagLayout.setConstraints(ipStsLabel, gridBagConstraints);
    contentPanel.add(ipStsLabel);

    final JTextField ipStsTextField = new JTextField(
            "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13",
            60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(ipStsTextField, gridBagConstraints);
    contentPanel.add(ipStsTextField);

    JLabel realmLabel = new JLabel("Realm:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(realmLabel, gridBagConstraints);
    contentPanel.add(realmLabel);

    JTextField realmTextField = new JTextField(AGIVSecurity.BETA_REALM, 30);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(realmTextField, gridBagConstraints);
    contentPanel.add(realmTextField);

    final CredentialPanel credentialPanel = new CredentialPanel();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(credentialPanel, gridBagConstraints);
    contentPanel.add(credentialPanel);

    final JLabel rStsLabel = new JLabel("R-STS:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = 1;
    gridBagLayout.setConstraints(rStsLabel, gridBagConstraints);
    contentPanel.add(rStsLabel);

    final JTextField rStsTextField = new JTextField(
            "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13",
            60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(rStsTextField, gridBagConstraints);
    contentPanel.add(rStsTextField);

    JLabel serviceRealmLabel = new JLabel("Service realm:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(serviceRealmLabel, gridBagConstraints);
    contentPanel.add(serviceRealmLabel);

    JTextField serviceRealmTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_REALM, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(serviceRealmTextField, gridBagConstraints);
    contentPanel.add(serviceRealmTextField);

    JLabel urlLabel = new JLabel("Service URL:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(urlLabel, gridBagConstraints);
    contentPanel.add(urlLabel);

    JTextField urlTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_LOCATION, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(urlTextField, gridBagConstraints);
    contentPanel.add(urlTextField);

    final JCheckBox noWsPolicyCheckBox = new JCheckBox("WSDL without WS-Policy");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(noWsPolicyCheckBox, gridBagConstraints);
    contentPanel.add(noWsPolicyCheckBox);

    final JCheckBox useWsSecureConversationCheckBox = new JCheckBox("Use WS-SecureConversation");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(useWsSecureConversationCheckBox, gridBagConstraints);
    contentPanel.add(useWsSecureConversationCheckBox);

    final JCheckBox usePreviousSecurityCheckBox = new JCheckBox("Use previous AGIV Security");
    final JCheckBox cancelPreviousSecureConversationToken = new JCheckBox("Cancel previous conversation token");
    usePreviousSecurityCheckBox.setEnabled(null != this.agivSecurity);
    cancelPreviousSecureConversationToken.setEnabled(false);
    usePreviousSecurityCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            LOG.debug("use previous security: " + usePreviousSecurityCheckBox.isSelected());
            boolean newSecurity = !usePreviousSecurityCheckBox.isSelected();
            ipStsLabel.setEnabled(newSecurity);
            ipStsTextField.setEditable(newSecurity);
            credentialPanel.setEnabled(newSecurity);
            rStsLabel.setEnabled(newSecurity);
            rStsTextField.setEnabled(newSecurity);
            cancelPreviousSecureConversationToken.setEnabled(!newSecurity);
        }
    });
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(usePreviousSecurityCheckBox, gridBagConstraints);
    contentPanel.add(usePreviousSecurityCheckBox);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(cancelPreviousSecureConversationToken, gridBagConstraints);
    contentPanel.add(cancelPreviousSecureConversationToken);

    JPanel expiresPanel = new JPanel();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = 2;
    gridBagLayout.setConstraints(expiresPanel, gridBagConstraints);
    contentPanel.add(expiresPanel);

    JLabel expiresLabelLabel = new JLabel("Secure conversation token expires:");
    expiresLabelLabel.setEnabled(null != this.agivSecurity);
    expiresPanel.add(expiresLabelLabel);

    JLabel expiresLabel = new JLabel();
    expiresLabel.setEnabled(null != this.agivSecurity);
    expiresPanel.add(expiresLabel);
    if (null != this.agivSecurity) {
        if (false == this.agivSecurity.getSecureConversationTokens().isEmpty()) {
            SecurityToken secureConversationToken = this.agivSecurity.getSecureConversationTokens().values()
                    .iterator().next();
            expiresLabel.setText(secureConversationToken.getExpires().toString());
        }
    }

    int dialogResult = JOptionPane.showConfirmDialog(this, contentPanel, "Claims Aware Service",
            JOptionPane.OK_CANCEL_OPTION);
    if (dialogResult == JOptionPane.CANCEL_OPTION) {
        return;
    }

    final String location = urlTextField.getText();
    final String serviceRealm = serviceRealmTextField.getText();
    final String ipStsLocation = ipStsTextField.getText();
    final String rStsLocation = rStsTextField.getText();
    final String username = credentialPanel.getUsername();
    final String password = credentialPanel.getPassword();
    final File pkcs12File = credentialPanel.getPKCS12File();
    final String realm = realmTextField.getText();

    ExecutorService executor = Executors.newFixedThreadPool(1);
    FutureTask<ArrayOfClaimInfo> futureTask = new FutureTask<ArrayOfClaimInfo>(
            new Callable<ArrayOfClaimInfo>() {

                public ArrayOfClaimInfo call() throws Exception {
                    Service service;
                    if (noWsPolicyCheckBox.isSelected()) {
                        service = ClaimsAwareServiceFactory.getInstanceNoWSPolicy();
                    } else {
                        service = ClaimsAwareServiceFactory.getInstance();
                    }
                    IService iservice = service.getWS2007FederationHttpBindingIService(new AddressingFeature());
                    BindingProvider bindingProvider = (BindingProvider) iservice;

                    if (false == usePreviousSecurityCheckBox.isSelected()) {
                        if (null != username) {
                            Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm,
                                    username, password);
                        } else {
                            Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm,
                                    pkcs12File, password);
                        }
                        Main.this.agivSecurity.addSTSListener(Main.this);
                        if (Main.this.proxyEnable) {
                            agivSecurity.setProxy(Main.this.proxyHost, Main.this.proxyPort,
                                    Main.this.proxyType);
                        }
                    }
                    if (cancelPreviousSecureConversationToken.isSelected()) {
                        Main.this.agivSecurity.cancelSecureConversationTokens();
                    }
                    Main.this.agivSecurity.enable(bindingProvider, location,
                            useWsSecureConversationCheckBox.isSelected(), serviceRealm);

                    ArrayOfClaimInfo result = iservice.getData(0);
                    return result;
                }
            }) {

        @Override
        protected void done() {
            try {
                ArrayOfClaimInfo result = get();
                List<ClaimInfo> claims = result.getClaimInfo();
                StringBuffer message = new StringBuffer();
                for (ClaimInfo claim : claims) {
                    message.append(claim.getName());
                    message.append(" = ");
                    message.append(claim.getValue());
                    message.append("\n");
                }

                JOptionPane.showMessageDialog(Main.this, message.toString(), "Claims Aware Service Result",
                        JOptionPane.INFORMATION_MESSAGE);
            } catch (final Exception e) {
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {

                        public void run() {
                            Main.this.statusBar.setErrorStatus(e.getMessage());
                        }
                    });
                } catch (Exception e1) {
                }
                showException(e);
            }
        }
    };
    executor.execute(futureTask);
}

From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

public void stepStarted(final TestStepContext context) {
    try {//  w  w  w.  j  a  v  a2 s  .c om
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                actionComponents.stepping();
                int stepIndex = context.getTestStep().getStepIndex();
                setCurrentStep(stepIndex);
                DebugStep debugStep = steps.get(currentRunningStep);
                if (debugStep != null) {
                    debugStep.setEntryVariables(context.getVariables().getVaribleValues());
                    debugStep.setRequest(context.getRequest());
                    debugStep.setResponse(context.getResponse());
                }
                fireStepChanged(stepIndex);
                fireStepStarted(stepIndex);
            }
        });
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}