Example usage for javax.swing SwingUtilities isEventDispatchThread

List of usage examples for javax.swing SwingUtilities isEventDispatchThread

Introduction

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

Prototype

public static boolean isEventDispatchThread() 

Source Link

Document

Returns true if the current thread is an AWT event dispatching thread.

Usage

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

private void updateRightClickMenu() {
    if (!SwingUtilities.isEventDispatchThread()) {
        String errMsg = "updateRightClickMenu is not on the EDT but it should be";
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }/*from w  ww. j  av  a2 s. c om*/
    ProfilePanelAdapter profileAdapter = profileModel.getProfileAdapter();
    if (profileAdapter != null) {
        boolean single = (getSelectedRowCount() == 1);
        openMenuItem.setEnabled(supportsOpenAction(selectedFile, single, profileAdapter));

        boolean showDelete = !currentDir.isVersionList()
                && supportsDeleteAction(selectedFile, single, profileAdapter) && !JobDialog.isOpen(); // Can't start a delete job when a job already exists
        deleteMenuItem.setEnabled(showDelete);

        boolean showSetMetadata = !currentDir.isVersionList()
                && supportsSetMetadataAction(selectedFile, single, profileAdapter) && !JobDialog.isOpen(); // Can't start a set metadata job when a job already
                                                                                                                                                                 // exists
        setMetadataMenuItem.setEnabled(showSetMetadata);

        boolean showRename = supportsRenameAction(selectedFile, single, profileAdapter) && !JobDialog.isOpen();
        renameMenuItem.setEnabled(showRename);

        refreshMenuItem.setEnabled(supportsRefreshAction(selectedFile, single, profileAdapter));

        boolean showMkdir = !currentDir.isVersionList()
                && supportsMkdirAction(selectedFile, single, profileAdapter);
        mkdirMenuItem.setEnabled(showMkdir);

        propertiesMenuItem.setEnabled(supportsPropertiesAction(selectedFile, single, profileAdapter));
    }
    browseMenuItem.setEnabled(FileSystemProfile.LOCAL_FILESYSTEM_PROFILE == getSelectedProfile());
}

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

/**
 * Refresh the content of the JComponents
 *//*from  ww  w. ja  v  a  2 s  . c  om*/
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:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java

/**
 * Appends a consecutive message to the document.
 *
 * @param chatMessage the message to append
 * @param keyword the keywords to highlight
 *//*from   ww  w . ja va 2 s .c  o m*/
public void appendConsecutiveMessage(final ChatMessage chatMessage, final String keyword) {
    String previousMessageUID = lastMessageUID;
    lastMessageUID = chatMessage.getMessageUID();

    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                appendConsecutiveMessage(chatMessage, keyword);
            }
        });
        return;
    }

    Element lastMsgElement = document.getElement(ChatHtmlUtils.MESSAGE_TEXT_ID + previousMessageUID);

    String contactAddress = (String) lastMsgElement.getAttributes().getAttribute(Attribute.NAME);

    boolean isHistory = (chatMessage.getMessageType().equals(Chat.HISTORY_INCOMING_MESSAGE)
            || chatMessage.getMessageType().equals(Chat.HISTORY_OUTGOING_MESSAGE)) ? true : false;

    String newMessage = ChatHtmlUtils.createMessageTag(chatMessage.getMessageUID(), contactAddress,
            formatMessageAsHTML(chatMessage.getMessage(), chatMessage.getContentType(), keyword),
            ChatHtmlUtils.HTML_CONTENT_TYPE, chatMessage.getDate(), false, isHistory, isSimpleTheme);

    synchronized (scrollToBottomRunnable) {
        try {
            Element parentElement = lastMsgElement.getParentElement();

            document.insertBeforeEnd(parentElement, newMessage);

            // Need to call explicitly scrollToBottom, because for some
            // reason the componentResized event isn't fired every time
            // we add text.
            SwingUtilities.invokeLater(scrollToBottomRunnable);
        } catch (BadLocationException ex) {
            logger.error("Could not replace chat message", ex);
        } catch (IOException ex) {
            logger.error("Could not replace chat message", ex);
        }
    }

    finishMessageAdd(newMessage);
}

From source file:com.kenai.redminenb.repository.RedmineRepository.java

public final RedmineManager getManager() throws RedmineException {
    assert (!SwingUtilities.isEventDispatchThread()) : "Access to Redmine Manager must happen outside EDT!";
    AuthMode authMode = getAuthMode();/*from   w  ww  . java 2 s.  com*/
    if (manager == null) {
        if (authMode == null) {
            throw new IllegalArgumentException("authMode must be set");
        }
        if (authMode == AuthMode.AccessKey) {
            manager = RedmineManagerFactory.createWithApiKey(getUrl(), getAccessKey(),
                    RedmineManagerFactory.createShortTermConfig(createConnectionManager()));
        } else {
            manager = RedmineManagerFactory.createWithUserAuth(getUrl(), getUsername(),
                    getPassword() == null ? "" : String.valueOf(getPassword()),
                    RedmineManagerFactory.createShortTermConfig(createConnectionManager()));
        }
        currentUser = new RedmineUser(manager.getUserManager().getCurrentUser(), true);
        manager.setObjectsPerPage(100);
    }
    return manager;
}

From source file:dr.app.bss.Utils.java

public static void showDialog(final String message) {

    if (SwingUtilities.isEventDispatchThread()) {

        JOptionPane.showMessageDialog(getActiveFrame(), message, "Message", JOptionPane.ERROR_MESSAGE,
                Utils.createImageIcon(Utils.BUBBLE_BLUE_ICON));

    } else {//from w  ww.  j a  v a 2  s. c  om
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                JOptionPane.showMessageDialog(getActiveFrame(), message, "Message", JOptionPane.ERROR_MESSAGE,
                        Utils.createImageIcon(Utils.BUBBLE_BLUE_ICON));

            }
        });
    } // END: edt check
}

From source file:com.eviware.soapui.SoapUI.java

public static synchronized void log(final Object msg) {
    if (logMonitor == null) {
        if (!isCommandLine && logCache.size() < 1000)
            logCache.add(msg);/*from  w  w w  .j a  v  a  2  s  . c  o m*/

        return;
    }

    if (SwingUtilities.isEventDispatchThread()) {
        logMonitor.logEvent(msg);
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                logMonitor.logEvent(msg);
            }
        });
    }
}

From source file:dr.app.bss.Utils.java

public static void handleException(final Throwable e, final String message) {

    final Thread t = Thread.currentThread();

    if (SwingUtilities.isEventDispatchThread()) {
        showExceptionDialog(t, e, message);
    } else {/*from   w w  w . j av a2  s. c o  m*/
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                showExceptionDialog(t, e, message);
            }
        });
    } // END: edt check
}

From source file:com.opendoorlogistics.studio.appframe.AppFrame.java

/**
 * Set the new datastore, which has already been decorated with listeners, undo / redo etc...
 * @param decoratedDs/*w w  w .  ja  v  a  2 s  . c  o  m*/
 * @param sourceFile
 */
@SuppressWarnings("unchecked")
void setDecoratedDatastore(ODLDatastoreUndoable<? extends ODLTableAlterable> decoratedDs,
        DatastoreManagerPluginState dmps, File sourceFile) {
    if (loaded != null) {
        closeDatastore();
    }

    loaded = new LoadedState(decoratedDs, sourceFile, this);

    DatastoreManagerPlugin plugin = DatastoreManagerGlobalPlugin.getPlugin();
    if (plugin != null && dmps != null) {
        loaded.putPluginState(plugin, dmps);
    }

    tables.setDatastore(loaded.getDs());

    decoratedDs.addListener(scriptManager);

    UndoStateChangedListener<ODLTableAlterable> undoStateChangedListener = new UndoStateChangedListener<ODLTableAlterable>() {

        @Override
        public void undoStateChanged(ODLDatastoreUndoable<? extends ODLTableAlterable> datastoreUndoable) {
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    for (UIAction action : allActions) {
                        if (action != null) {
                            action.updateEnabledState();
                        }
                    }
                }
            };

            if (SwingUtilities.isEventDispatchThread()) {
                runnable.run();
            } else {
                SwingUtilities.invokeLater(runnable);
            }
        }
    };

    // having java compilation oddities so we do the cast ... type erasure should ensure its safe
    ((ODLDatastoreUndoable<ODLTableAlterable>) decoratedDs).addUndoStateListener(undoStateChangedListener);

    updateAppearance();
    scriptManager.datastoreStructureChanged();
}

From source file:dr.app.bss.Utils.java

public static void handleException(final Throwable e) {

    final Thread t = Thread.currentThread();

    if (SwingUtilities.isEventDispatchThread()) {
        showExceptionDialog(t, e);//from  w  w w  .  j a va  2  s .c  om
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                showExceptionDialog(t, e);
            }
        });
    } // END: edt check
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java

/**
 * Replaces the contents of the message with ID of the corrected message
 * specified in chatMessage, with this message.
 *
 * @param chatMessage A <tt>ChatMessage</tt> that contains all the required
 * information to correct the old message.
 *///from  ww w .j ava 2  s. c  o m
public void correctMessage(final ChatMessage chatMessage) {
    lastMessageUID = chatMessage.getMessageUID();

    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                correctMessage(chatMessage);
            }
        });
        return;
    }

    String correctedUID = chatMessage.getCorrectedMessageUID();
    Element root = document.getDefaultRootElement();
    Element correctedMsgElement = document.getElement(root, Attribute.ID,
            ChatHtmlUtils.MESSAGE_TEXT_ID + correctedUID);

    if (correctedMsgElement == null) {
        logger.warn("Could not find message with ID " + correctedUID);
        return;
    }

    String contactAddress = (String) correctedMsgElement.getAttributes().getAttribute(Attribute.NAME);

    boolean isHistory = (chatMessage.getMessageType().equals(Chat.HISTORY_INCOMING_MESSAGE)
            || chatMessage.getMessageType().equals(Chat.HISTORY_OUTGOING_MESSAGE)) ? true : false;

    String newMessage = ChatHtmlUtils.createMessageTag(chatMessage.getMessageUID(), contactAddress,
            formatMessageAsHTML(chatMessage.getMessage(), chatMessage.getContentType(), ""),
            ChatHtmlUtils.HTML_CONTENT_TYPE, chatMessage.getDate(), true, isHistory, isSimpleTheme);

    synchronized (scrollToBottomRunnable) {
        try {
            document.setOuterHTML(correctedMsgElement, newMessage);

            // Need to call explicitly scrollToBottom, because for some
            // reason the componentResized event isn't fired every time
            // we add text.
            SwingUtilities.invokeLater(scrollToBottomRunnable);
        } catch (BadLocationException ex) {
            logger.error("Could not replace chat message", ex);
        } catch (IOException ex) {
            logger.error("Could not replace chat message", ex);
        }
    }

    finishMessageAdd(newMessage);
}