Beispiel #1
0
  /**
   * Checks for the latest update on the server.
   *
   * @param forced true if you want to bypass the normal checking security.
   */
  private void checkForUpdates(final boolean forced) {
    final CheckUpdates updater = new CheckUpdates();
    try {
      final SwingWorker updateThread =
          new SwingWorker() {
            public Object construct() {
              try {
                Thread.sleep(50);
              } catch (InterruptedException e) {
                Log.error(e);
              }
              return "ok";
            }

            public void finished() {
              try {
                updater.checkForUpdate(forced);
              } catch (Exception e) {
                Log.error("There was an error while checking for a new update.", e);
              }
            }
          };

      updateThread.start();

    } catch (Exception e) {
      Log.warning("Error updating.", e);
    }
  }
Beispiel #2
0
  private void saveNotes() {
    String note = textPane.getText();

    // Check for empty note.
    if (!ModelUtil.hasLength(note)) {
      return;
    }

    // Save note.
    AgentSession agentSession = FastpathPlugin.getAgentSession();
    try {
      agentSession.setNote(sessionID, note);
      saveButton.setEnabled(false);
      statusLabel.setText(" " + FpRes.getString("message.notes.updated"));
      SwingWorker worker =
          new SwingWorker() {
            public Object construct() {
              try {
                Thread.sleep(3000);
              } catch (InterruptedException e1) {
                Log.error(e1);
              }
              return true;
            }

            public void finished() {
              statusLabel.setText("");
            }
          };
      worker.start();
    } catch (XMPPException e1) {
      showError(FpRes.getString("message.unable.to.update.notes"));
      Log.error("Could not commit note.", e1);
    }
  }
Beispiel #3
0
  @Override
  public void initialize() {

    final SwingWorker bookmarkThreadWorker =
        new SwingWorker() {

          @Override
          public Object construct() {
            return this;
          }

          /** Installing menu into spark menu and adding events to bookmarks */
          @Override
          public void finished() {
            try {
              initialize();
            } catch (Exception e) {
              Log.error(e);
            }
          }

          /** */
          public void initialize() {
            final JMenu bookmarkMenu = new JMenu(Res.getString("menuitem.bookmarks"));

            createMenu(bookmarkMenu);

            if (bookmarkMenu.getMenuComponentCount() > 0) {
              SparkManager.getMainWindow().getMenu().add(bookmarkMenu, 3);
            }

            BookmarksUI bookmarksUi = ConferenceServices.getBookmarkedConferences();
            bookmarksUi.addBookmarksListener(
                new BookmarksListener() {

                  @Override
                  public void bookmarkAdded(String roomJID) {
                    rescan(bookmarkMenu);
                  }

                  @Override
                  public void bookmarkRemoved(String roomJID) {
                    rescan(bookmarkMenu);
                  }
                });
          }

          /**
           * Rescaning our bookmarks and remaking menu items
           *
           * @param Bookmark menu Jmenu
           */
          public void rescan(JMenu bookmarkMenu) {
            bookmarkMenu.removeAll(); // removing old menus
            try {
              setBookmarks(bookmarkMenu); // making new
              int onPanel = SparkManager.getMainWindow().getMenu().getComponentIndex(bookmarkMenu);

              if (onPanel < 0) {
                if (bookmarkMenu.getMenuComponentCount() > 0) {
                  int menuCount = SparkManager.getMainWindow().getMenu().getMenuCount();
                  SparkManager.getMainWindow().getMenu().add(bookmarkMenu, menuCount - 2);
                }
              }

              if (onPanel >= 0) {
                if (bookmarkMenu.getMenuComponentCount() <= 0) {
                  SparkManager.getMainWindow().getMenu().remove(bookmarkMenu);
                }
              }
              SparkManager.getMainWindow().getMenu().invalidate();
              SparkManager.getMainWindow().getMenu().validate();
              SparkManager.getMainWindow().getMenu().repaint();
            } catch (XMPPException ex) {
              Log.error(ex);
            }
          }

          /**
           * Updating statusbar and generating menu items
           *
           * @param Bookmark menu Jmenu
           */
          public void createMenu(JMenu bookmarkMenu) {
            try {
              setBookmarks(bookmarkMenu);
            } catch (XMPPException ex) {
              Log.error(ex);
            }
          }

          /**
           * loading menu items and setting bookmarks listeners
           *
           * @param Bookmark menu Jmenu
           */
          public void setBookmarks(JMenu bookmarkMenu) throws XMPPException {
            BookmarkManager manager =
                BookmarkManager.getBookmarkManager(SparkManager.getConnection());

            if (manager != null) {

              Collection<BookmarkedConference> bookmarkedConferences =
                  manager.getBookmarkedConferences();
              final Collection<BookmarkedURL> bookmarkedLinks = manager.getBookmarkedURLs();

              for (Object bookmarkedLink : bookmarkedLinks) {
                final BookmarkedURL link = (BookmarkedURL) bookmarkedLink;

                Action urlAction =
                    new AbstractAction() {

                      private static final long serialVersionUID = 4246574779205966917L;

                      @Override
                      public void actionPerformed(ActionEvent actionEvent) {
                        try {
                          BrowserLauncher.openURL(link.getURL());
                        } catch (Exception e) {
                          Log.error(e);
                        }
                      }
                    };

                urlAction.putValue(Action.NAME, link.getName());
                urlAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.LINK_16x16));
                bookmarkMenu.add(urlAction);
              }

              for (Object bookmarkedConference : bookmarkedConferences) {
                final BookmarkedConference conferences =
                    (BookmarkedConference) bookmarkedConference;

                Action conferenceAction =
                    new AbstractAction() {

                      private static final long serialVersionUID = 5964584172262968704L;

                      @Override
                      public void actionPerformed(ActionEvent actionEvent) {
                        final TimerTask task =
                            new SwingTimerTask() {

                              @Override
                              public void doRun() {
                                ConferenceUtils.joinConferenceOnSeperateThread(
                                    conferences.getName(),
                                    conferences.getJid(),
                                    conferences.getPassword());
                              }
                            };

                        TaskEngine.getInstance().schedule(task, 10);
                      }
                    };

                conferenceAction.putValue(Action.NAME, conferences.getName());
                conferenceAction.putValue(
                    Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.CONFERENCE_IMAGE_16x16));
                bookmarkMenu.add(conferenceAction);
              }
            }
          }
        };

    bookmarkThreadWorker.start();
  }