http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/dc466d6d/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffSidebarPanel.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffSidebarPanel.java b/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffSidebarPanel.java deleted file mode 100644 index 79ef03c..0000000 --- a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffSidebarPanel.java +++ /dev/null @@ -1,359 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their respective - * authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.ui.perspectives.myexperiment; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.Iterator; - -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.MyExperimentClient; -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.Resource; -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.User; -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.Util; -import net.sf.taverna.t2.workbench.file.FileManager; -import net.sf.taverna.t2.workbench.icons.WorkbenchIcons; - -import org.apache.log4j.Logger; - -/** - * @author Sergejs Aleksejevs, Emmanuel Tagarira, Jiten Bhagat - */ -public class MyStuffSidebarPanel extends JPanel implements ActionListener { - private final MainComponent pluginMainComponent; - private final MyExperimentClient myExperimentClient; - private final Logger logger; - - // main components of the SidebarPanel - private final JPanel jpMyProfileBox; - private final JPanel jpMyFriendsBox; - private final JPanel jpMyGroupsBox; - private final JPanel jpMyFavouritesBox; - private final JPanel jpMyTagsBox; - private JButton bLogout; - protected JButton bRefreshMyStuff; - private JButton bUpload; - - // icons which are used in several places in the sidebar - private final ImageIcon iconUser; - private final ImageIcon iconLogout; - private final FileManager fileManager; - - public MyStuffSidebarPanel(MainComponent component, MyExperimentClient client, Logger logger, FileManager fileManager) { - super(); - - // set main variables to ensure access to myExperiment, logger and the - // parent component - this.pluginMainComponent = component; - this.myExperimentClient = client; - this.logger = logger; - this.fileManager = fileManager; - - // prepare icons - iconUser = new ImageIcon(MyExperimentPerspective.getLocalIconURL(Resource.USER)); - iconLogout = new ImageIcon(MyExperimentPerspective.getLocalResourceURL("logout_icon")); - - // add elements of the sidebar - this.setLayout(new GridBagLayout()); - GridBagConstraints gbConstraints = new GridBagConstraints(); - gbConstraints.anchor = GridBagConstraints.NORTHWEST; - gbConstraints.fill = GridBagConstraints.HORIZONTAL; - gbConstraints.weightx = 1; - gbConstraints.gridx = 0; - - gbConstraints.gridy = 0; - jpMyProfileBox = createMyProfileBox(); - this.add(jpMyProfileBox, gbConstraints); - - gbConstraints.gridy = 1; - jpMyFriendsBox = createMyFriendsBox(); - this.add(jpMyFriendsBox, gbConstraints); - - gbConstraints.gridy = 2; - jpMyGroupsBox = createMyGroupsBox(); - this.add(jpMyGroupsBox, gbConstraints); - - gbConstraints.gridy = 3; - jpMyFavouritesBox = createMyFavouritesBox(); - repopulateFavouritesBox(); - this.add(jpMyFavouritesBox, gbConstraints); - - gbConstraints.gridy = 4; - jpMyTagsBox = createMyTagsBox(); - this.add(jpMyTagsBox, gbConstraints); - - // report that this component has been loaded - pluginMainComponent.getMyStuffTab().cdlComponentLoadingDone.countDown(); - } - - // creates a JPanel displaying the currently logged in user, logout button, - // etc - private JPanel createMyProfileBox() { - // panel containing name and avatar - JPanel jpAvatar = new JPanel(); - jpAvatar.setLayout(new BoxLayout(jpAvatar, BoxLayout.X_AXIS)); - - User currentUser = this.myExperimentClient.getCurrentUser(); - ImageIcon userAvatar = currentUser.getAvatar(); - JLabel jlUserAvatar = new JLabel("No Profile Picture Found"); - if (userAvatar != null) - jlUserAvatar = new JLabel(Util.getResizedImageIcon(userAvatar, 80, 80)); - - jlUserAvatar.setAlignmentX(LEFT_ALIGNMENT); - jpAvatar.add(jlUserAvatar); - - String name = "<html>"; - for (int x = 0; x < currentUser.getName().split(" ").length; x++) - name += currentUser.getName().split(" ")[x] + "<br>"; - name += "</html>"; - - JClickableLabel jclUserName = new JClickableLabel(name, "preview:" - + Resource.USER + ":" + currentUser.getURI(), pluginMainComponent.getPreviewBrowser(), this.iconUser); - jpAvatar.add(jclUserName); - - // panel containing everything in the profile box - JPanel jpEverythingInProfileBox = new JPanel(); - jpEverythingInProfileBox.setMaximumSize(new Dimension(1024, 0)); - jpEverythingInProfileBox.setLayout(new BoxLayout(jpEverythingInProfileBox, BoxLayout.X_AXIS)); - - jpEverythingInProfileBox.add(jpAvatar); - - // action buttons - bLogout = new JButton("Logout", iconLogout); - bLogout.addActionListener(this); - - bRefreshMyStuff = new JButton("Refresh", WorkbenchIcons.refreshIcon); - bRefreshMyStuff.addActionListener(this.pluginMainComponent.getMyStuffTab()); - - bUpload = new JButton("Upload Workflow", WorkbenchIcons.upArrowIcon); - bUpload.addActionListener(this); - - // panel for the buttons - JPanel jpButtons = new JPanel(); - jpButtons.setLayout(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridwidth = 1; - gbc.gridy = 0; - gbc.anchor = GridBagConstraints.NORTH; - gbc.fill = GridBagConstraints.BOTH; - gbc.gridx = 0; - - jpButtons.add(bUpload, gbc); - gbc.gridy++; - jpButtons.add(bRefreshMyStuff, gbc); - gbc.gridy++; - jpButtons.add(bLogout, gbc); - - jpEverythingInProfileBox.add(jpButtons); - - jpEverythingInProfileBox.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " My Profile "), BorderFactory.createEmptyBorder(1, 8, 8, 5))); - - return (jpEverythingInProfileBox); - } - - // creates a JPanel that displays a list of all friends of the current user - private JPanel createMyFriendsBox() { - JPanel jpFriends = new JPanel(); - jpFriends.setLayout(new BoxLayout(jpFriends, BoxLayout.Y_AXIS)); - - // iterate through all friends and add all to the panel - Iterator<HashMap<String, String>> iFriends = this.myExperimentClient.getCurrentUser().getFriends().iterator(); - if (iFriends.hasNext()) { - while (iFriends.hasNext()) { - HashMap<String, String> hmCurFriend = iFriends.next(); - jpFriends.add(new JClickableLabel(hmCurFriend.get("name"), "preview:" - + Resource.USER + ":" + hmCurFriend.get("uri"), pluginMainComponent.getPreviewBrowser(), this.iconUser)); - } - } else { - // known not to have any friends - JLabel lNone = new JLabel("None"); - lNone.setFont(lNone.getFont().deriveFont(Font.ITALIC)); - lNone.setForeground(Color.GRAY); - jpFriends.add(lNone); - } - - jpFriends.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " My Friends "), BorderFactory.createEmptyBorder(1, 8, 8, 5))); - - return (jpFriends); - } - - // generates a JPanel that displays a list of groups for current user - // when they are logged in - private JPanel createMyGroupsBox() { - JPanel jpGroups = new JPanel(); - - jpGroups.setLayout(new BoxLayout(jpGroups, BoxLayout.Y_AXIS)); - - // prepare the icon for groups - ImageIcon iconGroup = new ImageIcon(MyExperimentPerspective.getLocalIconURL(Resource.GROUP)); - - // iterate through all groups and add all to the panel - Iterator<HashMap<String, String>> iGroups = this.myExperimentClient.getCurrentUser().getGroups().iterator(); - if (iGroups.hasNext()) { - while (iGroups.hasNext()) { - HashMap<String, String> hmCurGroup = iGroups.next(); - jpGroups.add(new JClickableLabel(hmCurGroup.get("name"), "preview:" - + Resource.GROUP + ":" + hmCurGroup.get("uri"), pluginMainComponent.getPreviewBrowser(), iconGroup)); - } - } else { - // known not to have any groups - JLabel lNone = new JLabel("None"); - lNone.setFont(lNone.getFont().deriveFont(Font.ITALIC)); - lNone.setForeground(Color.GRAY); - jpGroups.add(lNone); - } - - jpGroups.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " My Groups "), BorderFactory.createEmptyBorder(1, 8, 8, 5))); - - return (jpGroups); - } - - // generates a JPanel that displays a list of favourite items for current user - // when they are logged in - private JPanel createMyFavouritesBox() { - JPanel jpFavourites = new JPanel(); - - jpFavourites.setLayout(new BoxLayout(jpFavourites, BoxLayout.Y_AXIS)); - jpFavourites.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " My Favourites "), BorderFactory.createEmptyBorder(1, 8, 8, 5))); - - return (jpFavourites); - } - - public void repopulateFavouritesBox() { - this.jpMyFavouritesBox.removeAll(); - - // iterate through all favourites and add all to the panel - Iterator<Resource> iFavourites = this.myExperimentClient.getCurrentUser().getFavourites().iterator(); - if (iFavourites.hasNext()) { - while (iFavourites.hasNext()) { - Resource rFavourite = iFavourites.next(); - this.jpMyFavouritesBox.add(new JClickableLabel(rFavourite.getTitle(), "preview:" - + rFavourite.getItemType() + ":" + rFavourite.getURI(), pluginMainComponent.getPreviewBrowser(), new ImageIcon(MyExperimentPerspective.getLocalIconURL(rFavourite.getItemType())))); - } - } else { - // known not to have any favourites - JLabel lNone = new JLabel("None"); - lNone.setFont(lNone.getFont().deriveFont(Font.ITALIC)); - lNone.setForeground(Color.GRAY); - this.jpMyFavouritesBox.add(lNone); - } - } - - // creates a Panel that shows all tags of the current user - private JPanel createMyTagsBox() { - JPanel jpTags = new JPanel(); - jpTags.setLayout(new BoxLayout(jpTags, BoxLayout.Y_AXIS)); - - // prepare the icon for tags - ImageIcon iconTag = new ImageIcon(MyExperimentPerspective.getLocalIconURL(Resource.TAG)); - - // iterate through all tags and add all to the panel - Iterator<HashMap<String, String>> iTags = this.myExperimentClient.getCurrentUser().getTags().iterator(); - if (iTags.hasNext()) { - while (iTags.hasNext()) { - String strCurTag = iTags.next().get("name"); - jpTags.add(new JClickableLabel(strCurTag, "tag:" + strCurTag, pluginMainComponent.getPreviewBrowser(), iconTag)); - } - } else { - // known not to have any tags - JLabel lNone = new JLabel("None"); - lNone.setFont(lNone.getFont().deriveFont(Font.ITALIC)); - lNone.setForeground(Color.GRAY); - jpTags.add(lNone); - } - - jpTags.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " My Tags "), BorderFactory.createEmptyBorder(1, 8, 8, 5))); - - return (jpTags); - } - - public JPanel getMyProfileBox() { - return (this.jpMyProfileBox); - } - - // listener of button clicks in the sidebar - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(bLogout)) { - // logout button was clicked - - try { - // "forget" login details - this.myExperimentClient.doLogout(); - } catch (Exception ex) { - logger.error("Error while trying to logout from myExperiment, exception:\n" - + ex); - } - - // repaint "myStuff" tab to display the login box again - this.pluginMainComponent.getStatusBar().setStatus(this.pluginMainComponent.getMyStuffTab().getClass().getName(), "Logging out"); - this.pluginMainComponent.getMyStuffTab().createAndInitialiseInnerComponents(); - this.pluginMainComponent.getMyStuffTab().revalidate(); - this.pluginMainComponent.getMyStuffTab().repaint(); - this.pluginMainComponent.getStatusBar().setStatus(this.pluginMainComponent.getMyStuffTab().getClass().getName(), null); - this.pluginMainComponent.getStatusBar().setCurrentUser(null); - - // remove "My Tags" from the tags browser tab and rerun last searches (tag - // & keyword) - // so that any "private" search results won't get shown anymore - this.pluginMainComponent.getTagBrowserTab().setMyTagsShown(false); - this.pluginMainComponent.getTagBrowserTab().getTagSearchResultPanel().clear(); - this.pluginMainComponent.getTagBrowserTab().rerunLastTagSearch(); - - this.pluginMainComponent.getSearchTab().getSearchResultPanel().clear(); - this.pluginMainComponent.getSearchTab().rerunLastSearch(); - - // TODO: also, update another tabs, so that they don't display any 'private' content? - } else if (e.getSource().equals(this.bUpload)) { - JFrame containingFrame = (JFrame) SwingUtilities.windowForComponent(this); - // UploadWorkflowDialog uploadWorkflowDialog = new UploadWorkflowDialog(containingFrame); - - // File workflowFile = null; - // JFileChooser jfsSelectFile = new JFileChooser(); - // if (jfsSelectFile.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) - // workflowFile = jfsSelectFile.getSelectedFile(); - // else - // return; - - UploadWorkflowDialog uploadWorkflowDialog = new UploadWorkflowDialog(containingFrame, true, fileManager); - - if (uploadWorkflowDialog.launchUploadDialogAndPostIfRequired()) - // true was returned so refresh the whole of the mystuff content panel - this.actionPerformed(new ActionEvent(this.bRefreshMyStuff, 0, "")); - - } - - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/dc466d6d/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffTabContentPanel.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffTabContentPanel.java b/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffTabContentPanel.java deleted file mode 100644 index 56e2dcf..0000000 --- a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/MyStuffTabContentPanel.java +++ /dev/null @@ -1,342 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their respective - * authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.ui.perspectives.myexperiment; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.util.concurrent.CountDownLatch; - -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextField; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; - -import net.sf.taverna.t2.lang.ui.ShadedLabel; -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.MyExperimentClient; -import net.sf.taverna.t2.workbench.file.FileManager; - -import org.apache.log4j.Logger; - -/** - * @author Sergejs Aleksejevs, Emmanuel Tagarira, Jiten Bhagat - */ -public class MyStuffTabContentPanel extends JPanel implements ActionListener, KeyListener { - private final MainComponent pluginMainComponent; - private final MyExperimentClient myExperimentClient; - private final Logger logger; - - // components that should be accessible from anywhere in this class - private JButton bLogin; - private JCheckBox cbLoginAutomatically; - private MyStuffSidebarPanel jpSidebar; - public JSplitPane spMyStuff; - - // synchronisation latch to let main thread know that all component-creation - // threads have been finished - protected CountDownLatch cdlComponentLoadingDone; - int NUMBER_OF_SUBCOMPONENTS = 2; - - // "return to" type of thing, so that after a certain action has been done, - // it is possible to switch to another tab in this tabbed view - protected JComponent cTabContentComponentToSwitchToAfterLogin = null; - private final FileManager fileManager; - - public MyStuffTabContentPanel(MainComponent component, MyExperimentClient client, Logger logger, FileManager fileManager) { - super(); - - // set main variables to ensure access to myExperiment, logger and the - // parent component - this.pluginMainComponent = component; - this.myExperimentClient = client; - this.logger = logger; - this.fileManager = fileManager; - } - - public void createAndInitialiseInnerComponents() { - // if there are any components, these will be removed - this.removeAll(); - cdlComponentLoadingDone = new CountDownLatch(NUMBER_OF_SUBCOMPONENTS); - - // based on the current status (logged in / anonymous user), decide which - // components to create and display - if (this.myExperimentClient.isLoggedIn()) { - jpSidebar = new MyStuffSidebarPanel(pluginMainComponent, myExperimentClient, logger, fileManager); - JPanel jpSidebarContainer = new JPanel(); - jpSidebarContainer.setLayout(new BorderLayout()); - jpSidebarContainer.add(jpSidebar, BorderLayout.NORTH); - JScrollPane spSidebar = new JScrollPane(jpSidebarContainer); - spSidebar.getVerticalScrollBar().setUnitIncrement(ResourcePreviewBrowser.PREFERRED_SCROLL); - spSidebar.setMinimumSize(new Dimension(jpSidebar.getMyProfileBox().getPreferredSize().width + 30, 0)); // +30 - // --> 10 for padding and 10 for vertical scroll bar + 10 extra current - // user is logged in to myExperiment, display all personal data - - spMyStuff = new JSplitPane(); - spMyStuff.setLeftComponent(spSidebar); - spMyStuff.setRightComponent(new MyStuffContributionsPanel(pluginMainComponent, myExperimentClient, logger)); - this.pluginMainComponent.getStatusBar().setCurrentUser(myExperimentClient.getCurrentUser().getName()); - - // set proportional sizes of the two panes as 30/70 percents of the total - // width of the SplitPane - // this can only be done after the SplitPane is made visible - hence the - // need for the listener below - pluginMainComponent.addComponentListener(new ComponentAdapter() { - @Override - public void componentShown(ComponentEvent e) { - javax.swing.JOptionPane.showMessageDialog(null, "component shown"); - // NB! This is only needed for use with test class, not when Taverna - // calls perspective!! - // the SplitPane wouldn't have loaded yet - wait until it does - try { - Thread.sleep(50); - } // 50ms is a tiny delay -- acceptable - catch (Exception ex) { /* do nothing */} - - // set the proportions in the SplitPane - spMyStuff.setDividerLocation(400); - } - }); - - // make sure that both panes will grow/shrink at the same rate if the - // size of the whole SplitPane is changed by resizing the window - spMyStuff.setResizeWeight(0.3); - spMyStuff.setOneTouchExpandable(true); - spMyStuff.setDividerLocation(400); - spMyStuff.setDoubleBuffered(true); - - // spMyStuff will be the only component in the Panel - this.setLayout(new BorderLayout()); - this.add(spMyStuff); - - // wait until two of the components finish loading and set the status to 'ready' - // (done in a new thread so that this doesn't freeze the plugin window) - new Thread("Waiting for myStuff data to load") { - @Override - public void run() { - try { - cdlComponentLoadingDone.await(); - pluginMainComponent.getStatusBar().setStatus(this.getClass().getName(), null); - } catch (InterruptedException ex) { /* do nothing for now */ - } - } - }.start(); - } else { // NOT logged in - // reset status in case of unsuccessful autologin - this.pluginMainComponent.getStatusBar().setStatus(this.getClass().getName(), null); - - // user isn't logged in, display login box only - JPanel jpLoginBoxContainer = new JPanel(); - jpLoginBoxContainer.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - jpLoginBoxContainer.add(createLoginBox(), c); - - // put everything together (welcome banner + login box) - this.setLayout(new BorderLayout()); - this.add(new ShadedLabel("Welcome to the myExperiment plugin. Please note that you can still use other tabs even " - + "if you don't have a user profile yet!", ShadedLabel.BLUE), BorderLayout.NORTH); - this.add(jpLoginBoxContainer, BorderLayout.CENTER); - } - } - - // generates JPanel containing a login box - private JPanel createLoginBox() { - JPanel jpLoginBox = new JPanel(); - jpLoginBox.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(10, 10, 10, 10))); - - jpLoginBox.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - - // label "Login to myExp" - c.gridwidth = GridBagConstraints.REMAINDER; - c.insets = new Insets(0, 0, 15, 0); - c.gridx = 0; - c.gridy = 0; - JLabel jlHeader = new JLabel("<html><b>Log in to myExperiment</b></html>"); - jlHeader.setFont(jlHeader.getFont().deriveFont((float) 13.0)); - jpLoginBox.add(jlHeader, c); - - // set values - c.weightx = 1; - c.gridwidth = 1; - c.anchor = GridBagConstraints.LINE_START; - c.insets = new Insets(0, 0, 3, 0); - c.ipadx = 10; - - // autologin checkbox and label - c.gridy++; - c.insets = new Insets(0, 0, 0, 3); - cbLoginAutomatically = new JCheckBox("Log in automatically (next time)"); - cbLoginAutomatically.setBorder(BorderFactory.createEmptyBorder()); // makes sure that this is aligned with text fields above - cbLoginAutomatically.addActionListener(this); - cbLoginAutomatically.addKeyListener(this); - jpLoginBox.add(cbLoginAutomatically, c); - - // login button - c.gridy++; - c.gridx = 0; - c.anchor = GridBagConstraints.CENTER; - c.gridwidth = GridBagConstraints.REMAINDER; - c.fill = GridBagConstraints.HORIZONTAL; - c.insets = new Insets(10, 0, 0, 0); - bLogin = new JButton("Login", new ImageIcon(MyExperimentPerspective.getLocalResourceURL("login_icon"))); - bLogin.setDefaultCapable(true); - bLogin.addKeyListener(this); - bLogin.addActionListener(this); - jpLoginBox.add(bLogin, c); - - // wrap contents into another panel to allow for some extra border around the contents - return (jpLoginBox); - } - - public MyStuffSidebarPanel getSidebar() { - return (this.jpSidebar); - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(this.bLogin)) { - // "Login" button clicked - pluginMainComponent.getStatusBar().setStatus(this.getClass().getName(), "Logging in"); - - // Make call to myExperiment API in a different thread - // (then use SwingUtilities.invokeLater to update the UI when ready). - new Thread("Login to myExperiment") { - @Override - public void run() { - logger.debug("Logging in to myExperiment"); - - try { - // do the actual "logging in" - boolean bLoginSuccessful = myExperimentClient.doLogin(); - - // check if need to store the login credentials and settings - if (bLoginSuccessful) { - // store the settings anyway (for instance, to clear stored login/password - // - when the 'remember me' tick is not checked anymore); - // however, need to check whether to store login details or not - - myExperimentClient.getSettings().put(MyExperimentClient.INI_AUTO_LOGIN, new Boolean(cbLoginAutomatically.isSelected()).toString()); - myExperimentClient.storeHistoryAndSettings(); - - // if logging in was successful, set the status to the start of fetching the data - pluginMainComponent.getStatusBar().setStatus(this.getClass().getName(), "Fetching user data"); - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - if (myExperimentClient.isLoggedIn()) { - // login successful, change view to "logged in" one - createAndInitialiseInnerComponents(); - - // ..also, load user's tag cloud - pluginMainComponent.getTagBrowserTab().setMyTagsShown(true); - pluginMainComponent.getTagBrowserTab().getMyTagPanel().refresh(); - - // ..also, refresh tag search results because these my include - // much more than - // during the previous search when the user was still not - // logged-in - pluginMainComponent.getTagBrowserTab().rerunLastTagSearch(); - - // ..also, refresh the keyword search results (as more items - // can now be found) - pluginMainComponent.getSearchTab().rerunLastSearch(); - - // if after logging it is needed to switch to other tab, - // that is done now - if (cTabContentComponentToSwitchToAfterLogin != null) { - pluginMainComponent.getMainTabs().setSelectedComponent(cTabContentComponentToSwitchToAfterLogin); - cTabContentComponentToSwitchToAfterLogin = null; - } - - logger.debug("Logged in to myExperiment successfully"); - } else { - // couldn't login - display error message - pluginMainComponent.getStatusBar().setStatus(this.getClass().getName(), null); - javax.swing.JOptionPane.showMessageDialog(null, "Unable to login to myExperiment - please check your login details", "myExperiment Plugin - Couldn't Login", JOptionPane.ERROR_MESSAGE); - } - } - }); - } - - } catch (Exception ex) { - logger.error("Exception on attempt to login to myExperiment:\n", ex); - } - } - }.start(); - - } else if (e.getSource().equals(this.jpSidebar.bRefreshMyStuff)) { - // this will re-fetch all user profile data and repopulate the whole of the 'My Stuff' tab - pluginMainComponent.getStatusBar().setStatus(this.getClass().getName(), "Refreshing user data"); - - new Thread("Refreshing myStuff tab data") { - @Override - public void run() { - // re-fetch user data first - myExperimentClient.setCurrentUser(myExperimentClient.fetchCurrentUser(myExperimentClient.getCurrentUser().getURI())); - createAndInitialiseInnerComponents(); - revalidate(); - } - }.start(); - } - } - - // *** Callbacks for KeyListener interface *** - public void keyPressed(KeyEvent e) { - // ENTER pressed - check which element is the source and determine what - // acion is to be taken - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - if (e.getSource().equals(this.cbLoginAutomatically) - || e.getSource().equals(this.bLogin)) { - // ENTER pressed when focus was on the login button, one of checkboxes or the password field - do logging in - actionPerformed(new ActionEvent(this.bLogin, 0, "")); - } - } - } - - public void keyReleased(KeyEvent e) { - // do nothing - } - - public void keyTyped(KeyEvent e) { - // do nothing - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/dc466d6d/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginPreferencesDialog.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginPreferencesDialog.java b/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginPreferencesDialog.java deleted file mode 100644 index 2ad8a42..0000000 --- a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginPreferencesDialog.java +++ /dev/null @@ -1,372 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their respective - * authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.ui.perspectives.myexperiment; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.util.ArrayList; - -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.MyExperimentClient; -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.Util; -import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog; - -import org.apache.log4j.Logger; - -/** - * @author Sergejs Aleksejevs, Emmanuel Tagarira - */ -public class PluginPreferencesDialog extends HelpEnabledDialog implements ComponentListener, ActionListener { - // CONSTANTS - - // components for accessing application's main elements - private final MainComponent pluginMainComponent; - private final MyExperimentClient myExperimentClient; - private final Logger logger; - - // COMPONENTS - private JTextField tfMyExperimentURL; - private JComboBox cbDefaultLoggedInTab; - private JComboBox cbDefaultNotLoggedInTab; - private JCheckBox cbMyStuffWorkflows; - private JCheckBox cbMyStuffFiles; - private JCheckBox cbMyStuffPacks; - private JButton bSave; - private JButton bCancel; - private JClickableLabel jclClearPreviewHistory; - private JClickableLabel jclClearSearchHistory; - private JClickableLabel jclClearFavouriteSearches; - - // DATA STORAGE - private final Component[] pluginTabComponents; - private final ArrayList<String> alPluginTabComponentNames; - - public PluginPreferencesDialog(JFrame owner, MainComponent component, MyExperimentClient client, Logger logger) { - super(owner, "Plugin preferences", true); - - // set main variables to ensure access to myExperiment, logger and the parent component - this.pluginMainComponent = component; - this.myExperimentClient = client; - this.logger = logger; - - // set options of the preview dialog box - this.addComponentListener(this); - //this.setIconImage(new ImageIcon(MyExperimentPerspective.getLocalResourceURL("myexp_icon")).getImage()); - - // prepare plugin tab names to display in the UI afterwards - this.alPluginTabComponentNames = new ArrayList<String>(); - this.pluginTabComponents = this.pluginMainComponent.getMainTabs().getComponents(); - for (int i = 0; i < this.pluginTabComponents.length; i++) { - alPluginTabComponentNames.add(this.pluginMainComponent.getMainTabs().getTitleAt(i)); - } - - this.initialiseUI(); - - // this is not computation-intensive method, so no need to run in a new thread - this.initialiseData(); - } - - private void initialiseUI() { - // this constraints instance will be shared among all components in the window - GridBagConstraints c = new GridBagConstraints(); - - // create the myExperiment API address box - JPanel jpApiLocation = new JPanel(); - jpApiLocation.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " myExperiment Location "), BorderFactory.createEmptyBorder(0, 5, 5, 5))); - jpApiLocation.setLayout(new GridBagLayout()); - - c.gridx = 0; - c.gridy = 0; - c.weightx = 1.0; - c.anchor = GridBagConstraints.WEST; - jpApiLocation.add(new JLabel("Base URL of myExperiment instance to connect to"), c); - - c.gridy = 1; - c.fill = GridBagConstraints.HORIZONTAL; - this.tfMyExperimentURL = new JTextField(); - this.tfMyExperimentURL.setToolTipText("<html>Here you can specify the base URL of the myExperiment " - + "instance that you wish to connect to.<br>This allows the plugin to connect not only to the " - + "<b>main myExperiment website</b> (default value:<br><b>http://www.myexperiment.org</b>) but " - + "also to any other myExperiment instance that might<br>exist elsewhere.<br><br>It is recommended " - + "that you only change this setting if you are certain in your actions.</html>"); - jpApiLocation.add(this.tfMyExperimentURL, c); - - // create startup tab choice box - JPanel jpStartupTabChoice = new JPanel(); - jpStartupTabChoice.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Plugin Start-up Settings "), BorderFactory.createEmptyBorder(0, 5, 5, 5))); - jpStartupTabChoice.setLayout(new GridBagLayout()); - - c.gridx = 0; - c.gridy = 0; - c.weightx = 0; - c.insets = new Insets(0, 0, 0, 10); - jpStartupTabChoice.add(new JLabel("Default startup tab for anonymous user"), c); - - c.gridx = 1; - c.weightx = 1.0; - c.insets = new Insets(0, 0, 2, 0); - this.cbDefaultNotLoggedInTab = new JComboBox(this.alPluginTabComponentNames.toArray()); - this.cbDefaultNotLoggedInTab.setToolTipText("<html>This tab will be automatically opened at plugin start up time if you are <b>not</b> logged id to myExperiment.</html>"); - jpStartupTabChoice.add(this.cbDefaultNotLoggedInTab, c); - - c.gridx = 0; - c.gridy = 1; - c.weightx = 0; - c.insets = new Insets(0, 0, 0, 10); - jpStartupTabChoice.add(new JLabel("Default startup tab after successful auto-login"), c); - - c.gridx = 1; - c.weightx = 1.0; - c.insets = new Insets(2, 0, 0, 0); - this.cbDefaultLoggedInTab = new JComboBox(this.alPluginTabComponentNames.toArray()); - this.cbDefaultLoggedInTab.setToolTipText("<html>This tab will be automatically opened at plugin start up time if you have chosen to use <b>auto logging in</b> to myExperiment.</html>"); - jpStartupTabChoice.add(this.cbDefaultLoggedInTab, c); - - // create 'my stuff' tab preference box - JPanel jpMyStuffPrefs = new JPanel(); - jpMyStuffPrefs.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " 'My Stuff' Tab Settings "), BorderFactory.createEmptyBorder(0, 5, 5, 5))); - jpMyStuffPrefs.setLayout(new GridBagLayout()); - - c.gridx = 0; - c.gridy = 0; - c.weightx = 0; - c.insets = new Insets(0, 0, 0, 0); - jpMyStuffPrefs.add(new JLabel("Sections to show in this tab:"), c); - - c.gridx = 1; - c.gridy = 0; - c.weightx = 1.0; - c.insets = new Insets(0, 10, 0, 0); - this.cbMyStuffWorkflows = new JCheckBox("My Workflows"); - jpMyStuffPrefs.add(this.cbMyStuffWorkflows, c); - - c.gridy = 1; - this.cbMyStuffFiles = new JCheckBox("My Files"); - jpMyStuffPrefs.add(this.cbMyStuffFiles, c); - - c.gridy = 2; - this.cbMyStuffPacks = new JCheckBox("My Packs"); - jpMyStuffPrefs.add(this.cbMyStuffPacks, c); - - // create privacy settings box - JPanel jpPrivacySettings = new JPanel(); - jpPrivacySettings.setLayout(new BoxLayout(jpPrivacySettings, BoxLayout.Y_AXIS)); - jpPrivacySettings.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Privacy Settings "), BorderFactory.createEmptyBorder(0, 7, 5, 5))); - - this.jclClearPreviewHistory = new JClickableLabel("Clear browsing history", "clear_preview_history", this); - jpPrivacySettings.add(this.jclClearPreviewHistory); - - this.jclClearSearchHistory = new JClickableLabel("Clear search history", "clear_search_history", this); - this.jclClearSearchHistory.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0)); - jpPrivacySettings.add(this.jclClearSearchHistory); - - this.jclClearFavouriteSearches = new JClickableLabel("Clear favourite searches", "clear_favourite_searches", this); - this.jclClearFavouriteSearches.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); - jpPrivacySettings.add(this.jclClearFavouriteSearches); - - // create button panel - this.bSave = new JButton("Save"); - this.bSave.addActionListener(this); - - this.bCancel = new JButton("Cancel"); - this.bCancel.addActionListener(this); - - JPanel jpButtons = new JPanel(); - jpButtons.setLayout(new GridBagLayout()); - - c.gridx = 0; - c.gridy = 0; - c.weightx = 0; - c.insets = new Insets(0, 0, 0, 2); - jpButtons.add(bSave, c); - - c.gridx = 1; - c.insets = new Insets(0, 2, 0, 0); - jpButtons.add(bCancel, c); - - // PUT EVERYTHING TOGETHER - this.setTitle("myExperiment Plugin Preferences"); - BorderLayout layout = new BorderLayout(); - JPanel jpEverything = new JPanel(); - GridBagLayout jpEverythingLayout = new GridBagLayout(); - jpEverything.setLayout(jpEverythingLayout); - this.getContentPane().setLayout(layout); - - GridBagConstraints gbConstraints = new GridBagConstraints(); - gbConstraints.fill = GridBagConstraints.BOTH; - gbConstraints.weightx = 1; - gbConstraints.gridx = 0; - - gbConstraints.gridy = 0; - jpEverything.add(jpApiLocation, gbConstraints); - - gbConstraints.gridy = 1; - jpEverything.add(jpStartupTabChoice, gbConstraints); - - gbConstraints.gridy = 2; - jpEverything.add(jpMyStuffPrefs, gbConstraints); - - gbConstraints.gridy = 3; - jpEverything.add(jpPrivacySettings, gbConstraints); - - gbConstraints.gridy = 4; - jpEverything.add(jpButtons, gbConstraints); - - this.add(jpEverything); - this.setResizable(false); - - // pack() sets preferred size of the dialog box; - // after this, can set the minimum size to that value too - this.pack(); - this.setMinimumSize(this.getPreferredSize()); - } - - private void initialiseData() { - // myExperiment Base URL - this.tfMyExperimentURL.setText(myExperimentClient.getSettings().getProperty(MyExperimentClient.INI_BASE_URL)); - - // default tabs - this.cbDefaultNotLoggedInTab.setSelectedIndex(Integer.parseInt(myExperimentClient.getSettings().getProperty(MyExperimentClient.INI_DEFAULT_ANONYMOUS_TAB))); - this.cbDefaultLoggedInTab.setSelectedIndex(Integer.parseInt(myExperimentClient.getSettings().getProperty(MyExperimentClient.INI_DEFAULT_LOGGED_IN_TAB))); - - // components of "My Stuff" tab - this.cbMyStuffWorkflows.setSelected(Boolean.parseBoolean(myExperimentClient.getSettings().getProperty(MyExperimentClient.INI_MY_STUFF_WORKFLOWS))); - this.cbMyStuffFiles.setSelected(Boolean.parseBoolean(myExperimentClient.getSettings().getProperty(MyExperimentClient.INI_MY_STUFF_FILES))); - this.cbMyStuffPacks.setSelected(Boolean.parseBoolean(myExperimentClient.getSettings().getProperty(MyExperimentClient.INI_MY_STUFF_PACKS))); - } - - // *** Callbacks for ComponentListener interface *** - - public void componentShown(ComponentEvent e) { - // every time the settings window is shown, make sure that the dialog box appears - // centered horizontally and vertically relatively to the main component - Util.centerComponentWithinAnother(this.pluginMainComponent, this); - - // also, need to make sure that correct settings get shown - // (e.g. especially relevant when this window was last closed with 'cancel', - // but some options were changed prior to that) - this.initialiseData(); - } - - public void componentHidden(ComponentEvent e) { - // do nothing - } - - public void componentResized(ComponentEvent e) { - // do nothing - } - - public void componentMoved(ComponentEvent e) { - // do nothing - } - - // *** Callback for ActionListener interface *** - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(this.bSave)) { - // check if myExperiment address is present - String strNewMyExperimentURL = this.tfMyExperimentURL.getText().trim(); - if (strNewMyExperimentURL.length() == 0) { - javax.swing.JOptionPane.showMessageDialog(null, "Please specify a base URL of myExperiment instance that you wish to connect to", "Error", JOptionPane.WARNING_MESSAGE); - this.tfMyExperimentURL.requestFocusInWindow(); - return; - } - - // check if at least one of the checkboxes (for sections in 'My Stuff' tab) is selected - if (!(this.cbMyStuffWorkflows.isSelected() - || this.cbMyStuffFiles.isSelected() || this.cbMyStuffPacks.isSelected())) { - javax.swing.JOptionPane.showMessageDialog(null, "Please choose at least one section to display in 'My Stuff' tab", "Error", JOptionPane.WARNING_MESSAGE); - this.cbMyStuffWorkflows.requestFocusInWindow(); - return; - } - - // NB! changed myExperiment location will not take action until the next application restart - if (!strNewMyExperimentURL.equals(myExperimentClient.getBaseURL())) { - // turn off auto-login - myExperimentClient.getSettings().put(MyExperimentClient.INI_AUTO_LOGIN, new Boolean(false).toString()); - - javax.swing.JOptionPane.showMessageDialog(null, "You have selected a new Base URL for myExperiment. " - + "Your new setting has been saved,\nbut will not take effect until you restart Taverna.\n\n" - + "Auto-login feature has been switched off for you to check the login details at the next launch.", "myExperiment Plugin - Info", JOptionPane.INFORMATION_MESSAGE); - } - - // all values should be present - store these into Properties object - myExperimentClient.getSettings().put(MyExperimentClient.INI_BASE_URL, strNewMyExperimentURL); - myExperimentClient.getSettings().put(MyExperimentClient.INI_DEFAULT_ANONYMOUS_TAB, new Integer(cbDefaultNotLoggedInTab.getSelectedIndex()).toString()); - myExperimentClient.getSettings().put(MyExperimentClient.INI_DEFAULT_LOGGED_IN_TAB, new Integer(cbDefaultLoggedInTab.getSelectedIndex()).toString()); - myExperimentClient.getSettings().put(MyExperimentClient.INI_MY_STUFF_WORKFLOWS, new Boolean(cbMyStuffWorkflows.isSelected()).toString()); - myExperimentClient.getSettings().put(MyExperimentClient.INI_MY_STUFF_FILES, new Boolean(cbMyStuffFiles.isSelected()).toString()); - myExperimentClient.getSettings().put(MyExperimentClient.INI_MY_STUFF_PACKS, new Boolean(cbMyStuffPacks.isSelected()).toString()); - - // close the window eventually - setVisible(false); - } else if (e.getSource().equals(this.bCancel)) { - // simply close the preferences window - setVisible(false); - } else if (e.getSource().equals(this.jclClearPreviewHistory)) { - // request user confirmation and clear browsing history (preview history) - if (JOptionPane.showConfirmDialog(null, "This will delete the browsing history - the lists of previously previewed,\n" - + "downloaded, opened and commented on items will be emptied.\n\nDo you want to proceed?", "myExperiment Plugin - Confirmation Required", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - pluginMainComponent.getPreviewBrowser().clearPreviewHistory(); - pluginMainComponent.getHistoryBrowser().clearDownloadedItemsHistory(); - pluginMainComponent.getHistoryBrowser().clearOpenedItemsHistory(); - pluginMainComponent.getHistoryBrowser().clearCommentedOnItemsHistory(); - pluginMainComponent.getHistoryBrowser().refreshHistoryBox(HistoryBrowserTabContentPanel.PREVIEWED_ITEMS_HISTORY); - pluginMainComponent.getHistoryBrowser().refreshHistoryBox(HistoryBrowserTabContentPanel.DOWNLOADED_ITEMS_HISTORY); - pluginMainComponent.getHistoryBrowser().refreshHistoryBox(HistoryBrowserTabContentPanel.OPENED_ITEMS_HISTORY); - pluginMainComponent.getHistoryBrowser().refreshHistoryBox(HistoryBrowserTabContentPanel.COMMENTED_ON_ITEMS_HISTORY); - } - } else if (e.getSource().equals(this.jclClearSearchHistory)) { - // request user confirmation and clear search history (tag search history + query search history) - if (JOptionPane.showConfirmDialog(null, "This will delete both query and tag search history.\nDo you want to proceed?", "myExperiment Plugin - Confirmation Required", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - pluginMainComponent.getSearchTab().getSearchHistory().clear(); - pluginMainComponent.getTagBrowserTab().getTagSearchHistory().clear(); - pluginMainComponent.getSearchTab().updateSearchHistory(); - pluginMainComponent.getHistoryBrowser().refreshSearchHistory(); - pluginMainComponent.getHistoryBrowser().refreshTagSearchHistory(); - } - } else if (e.getSource().equals(this.jclClearFavouriteSearches)) { - // request user confirmation and clear favourite searches - if (JOptionPane.showConfirmDialog(null, "This will delete all your favourite search settings.\nDo you want to proceed?", "myExperiment Plugin - Confirmation Required", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - pluginMainComponent.getSearchTab().getSearchFavouritesList().clear(); - pluginMainComponent.getSearchTab().updateFavouriteSearches(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/dc466d6d/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginStatusBar.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginStatusBar.java b/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginStatusBar.java deleted file mode 100644 index 0d68811..0000000 --- a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/PluginStatusBar.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their respective - * authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.ui.perspectives.myexperiment; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import javax.swing.BorderFactory; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; - -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.MyExperimentClient; -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.Util; -import net.sf.taverna.t2.workbench.icons.WorkbenchIcons; - -import org.apache.log4j.Logger; - -/** - * @author Sergejs Aleksejevs, Emmanuel Tagarira - */ -public class PluginStatusBar extends JPanel implements ActionListener { - // CONSTANTS - private static final String STATUS_MESSAGE_READY = "Ready"; - - private MainComponent pluginMainComponent; - private MyExperimentClient myExperimentClient; - private Logger logger; - - // all components that represent the status - private JLabel lSpinnerIcon; - private JLabel lStatusMsg; - private JLabel lCurrentUser; - // private JButton bPreferences; - - // collections to keep the statuses for different tabs - ArrayList<String> alTabClassNames; - ArrayList<String> alTabStatuses; - - // spinner icons - ImageIcon iconSpinner; - ImageIcon iconSpinnerStopped; - - public PluginStatusBar(MainComponent component, MyExperimentClient client, Logger logger) { - super(); - - // set main variables to ensure access to myExperiment, logger and the - // parent component - this.pluginMainComponent = component; - this.myExperimentClient = client; - this.logger = logger; - - // prepare status collections for different tabs - alTabClassNames = new ArrayList<String>(); - alTabStatuses = new ArrayList<String>(); - - // load icons - this.iconSpinner = new ImageIcon(MyExperimentPerspective.getLocalResourceURL("spinner")); - this.iconSpinnerStopped = new ImageIcon(MyExperimentPerspective.getLocalResourceURL("spinner_stopped")); - - // prepare main panel for the status bar - this.setLayout(new BorderLayout()); - this.setBorder(BorderFactory.createEmptyBorder(1, 4, 1, 1)); // this will - // add a bit - // more spacing - // on the left - // - before the - // status - // message - - // prepare status labels - this.lSpinnerIcon = new JLabel("", iconSpinnerStopped, SwingConstants.LEFT); - this.lStatusMsg = new JLabel("Ready"); - this.lCurrentUser = new JLabel("Please log in to access your profile", SwingConstants.CENTER); - - // 'Plugin Preferences' button - // this.bPreferences = new JButton("Plugin Preferences", WorkbenchIcons.configureIcon); - // this.bPreferences.addActionListener(this); - - // put everything together - JPanel pWestStatusBarSection = new JPanel(); - pWestStatusBarSection.add(lSpinnerIcon); - pWestStatusBarSection.add(lStatusMsg); - - this.add(pWestStatusBarSection, BorderLayout.WEST); - this.add(this.lCurrentUser, BorderLayout.EAST); - // this.add(this.bPreferences, BorderLayout.EAST); - } - - // updates the current user name in the middle of the status bar - public void setCurrentUser(String strUsername) { - // if "null" or "" is submitted as a parameter, the status will be set to - // "Ready" - if (strUsername == null || strUsername.length() == 0) - this.lCurrentUser.setText("Please log in to access your profile"); - else - this.lCurrentUser.setText("<html>Logged in as <b>" + strUsername - + "</b></html>"); - } - - // sets the status message to the one that is relevant to the current tab - public void displayStatus(String strTabClassName) { - int iTabIdx = -1; - String strBaseClassName = Util.getBaseClassName(strTabClassName); - - if ((iTabIdx = alTabClassNames.indexOf(strBaseClassName)) != -1) { - // tab found - show its status message - String strCurStatus = alTabStatuses.get(iTabIdx); - this.lStatusMsg.setText(strCurStatus); - startSpinner(!strCurStatus.equals(PluginStatusBar.STATUS_MESSAGE_READY)); - } else { - // tab not found - assume no actions are happening - // (this will create the 'ready' status for the current tab, - // then return to display it) - setStatus(strBaseClassName, null); - } - } - - // sets the status message for a particular tab; - // if this tab is currently active, the status will get displayed immediately - // (alternatively it will be displayed at the time when the tab becomes - // active) - public void setStatus(String strTabClassName, String strStatus) { - // PREPROCESSING - if "null" or "" is submitted as a parameter, the status - // will be set to "Ready" - if (strStatus == null || strStatus.length() == 0) - strStatus = PluginStatusBar.STATUS_MESSAGE_READY; - String strBaseClassName = Util.getBaseClassName(strTabClassName); - - // STORING the status it in the collection - int iTabIdx = -1; - if ((iTabIdx = alTabClassNames.indexOf(strBaseClassName)) != -1) { - // only a change of status, already dealt with this tab before - alTabStatuses.set(iTabIdx, strStatus); - } else { - // never worked with this tab before, add new one - alTabClassNames.add(strBaseClassName); - alTabStatuses.add(strStatus); - } - - // display the new status if the updated status is on the active tab - if (isTabActive(strBaseClassName)) - displayStatus(strBaseClassName); - } - - // helper to start / stop the spinner in the status bar that - // indicates that some action is currently in progress - // (action will be displayed by lStatusMsg label) - public void startSpinner(boolean bStart) { - this.lSpinnerIcon.setIcon(bStart ? this.iconSpinner : this.iconSpinnerStopped); - } - - // Determine whether the tab in the parameter is currently active in the main - // tabbed pane. - private boolean isTabActive(String strTabClassName) { - // get the current active tab (this is a normal class name of the main tab - // content component) - String strCurSelectedTabClassName = this.pluginMainComponent.getMainTabs().getSelectedComponent().getClass().getName(); - - // get the real class name to match - String strBaseClassName = Util.getBaseClassName(strTabClassName); - - // compare the two class names - return (strBaseClassName.equals(strCurSelectedTabClassName)); - } - - public void actionPerformed(ActionEvent e) { - // if (e.getSource().equals(this.bPreferences)) { - // // open preferences dialog box - // pluginMainComponent.getPreferencesDialog().setVisible(true); - // } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/dc466d6d/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/ResourceListPanel.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/ResourceListPanel.java b/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/ResourceListPanel.java deleted file mode 100644 index d0b00a3..0000000 --- a/taverna-workbench-perspective-myexperiment/src/main/java/net/sf/taverna/t2/ui/perspectives/myexperiment/ResourceListPanel.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2009 The University of Manchester - * - * Modifications to the initial code base are copyright of their respective - * authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.ui.perspectives.myexperiment; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Desktop; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.net.URI; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.event.HyperlinkEvent; -import javax.swing.event.HyperlinkListener; - -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.MyExperimentClient; -import net.sf.taverna.t2.ui.perspectives.myexperiment.model.Resource; -import org.apache.log4j.Logger; - -/** - * @author Sergejs Aleksejevs, Emmanuel Tagarira, Jiten Bhagat - */ -public class ResourceListPanel extends JPanel implements HyperlinkListener { - // CONSTANTS - public final static int DESCRIPTION_TRUNCATE_LENGTH_FOR_SHORT_LIST_VIEW = 150; - - public final static int THUMBNAIL_WIDTH_FOR_SHORT_LIST_VIEW = 60; - public final static int THUMBNAIL_HEIGHT_FOR_SHORT_LIST_VIEW = 45; - - public final static int THUMBNAIL_WIDTH_FOR_FULL_LIST_VIEW = 90; - public final static int THUMBNAIL_HEIGHT_FOR_FULL_LIST_VIEW = 90; - - private MainComponent pluginMainComponent; - private MyExperimentClient myExperimentClient; - private Logger logger; - - private JPanel listPanel; - private GridBagConstraints gbConstraints; - - private List<Resource> listItems; - - // some of the components will not be shown in the item list if - // it's not of full size - private boolean bFullSizeItemsList = true; - - public ResourceListPanel(MainComponent component, MyExperimentClient client, Logger logger) { - super(); - - // set main variables to ensure access to myExperiment, logger and the - // parent component - this.pluginMainComponent = component; - this.myExperimentClient = client; - this.logger = logger; - - this.initialiseUI(); - } - - public boolean isFullSizeItemsList() { - return this.bFullSizeItemsList; - } - - public void setFullSizeItemsList(boolean bFullSizeItemsList) { - this.bFullSizeItemsList = bFullSizeItemsList; - } - - public void hyperlinkUpdate(HyperlinkEvent e) { - try { - if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - String strAction = e.getDescription().toString(); - - if (strAction.startsWith("preview:")) { - this.pluginMainComponent.getPreviewBrowser().preview(strAction); - } else { - Desktop.getDesktop().browse(new URI(strAction)); - } - } - } catch (Exception ex) { - logger.error("Error occurred whilst clicking a hyperlink", ex); - } - } - - public void setListItems(List<Resource> items) { - this.listItems = items; - - this.repopulate(); - } - - public void clear() { - this.listPanel.removeAll(); - this.invalidate(); - } - - public void refresh() { - if (this.listItems != null) { - this.repopulate(); - } - } - - public void repopulate() { - if (this.listItems != null) { - this.clear(); - - if (this.listItems.size() > 0) { - Resource res = null; - for (int i = 0; i < this.listItems.size(); i++) { - try { - // this will make the layout manager to push all extra space in - // Y-axis - // to go to the last element in the panel; essentially, this will - // push - // all list items to the top of the list view panel - if (i == listItems.size() - 1) - gbConstraints.weighty = 1.0; - - res = this.listItems.get(i); - this.listPanel.add(res.createListViewPanel(bFullSizeItemsList, pluginMainComponent, this, logger), gbConstraints); - logger.debug("Added entry in resource list panel for the resource (Type: " - + res.getItemTypeName() + ", URI: " + res.getURI() + ")"); - } catch (Exception e) { - logger.error("Failed to add item entry to ResourceListPanel (Item Type : " - + res.getItemTypeName() + ", URI: " + res.getURI() + ")", e); - } - } - } else { - // no items in the list - JLabel lNone = new JLabel("None"); - lNone.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); - lNone.setForeground(Color.GRAY); - lNone.setFont(lNone.getFont().deriveFont(Font.ITALIC)); - - gbConstraints.anchor = GridBagConstraints.WEST; - this.listPanel.add(lNone, gbConstraints); - - this.listPanel.setPreferredSize(new Dimension(20, 40)); - this.listPanel.setBackground(Color.WHITE); - } - } - - this.validate(); - this.repaint(); - } - - private void initialiseUI() { - this.listPanel = new JPanel(); - this.listPanel.setBorder(BorderFactory.createEmptyBorder()); - - this.listPanel.setLayout(new GridBagLayout()); - this.gbConstraints = new GridBagConstraints(); - this.gbConstraints.anchor = GridBagConstraints.NORTH; - this.gbConstraints.fill = GridBagConstraints.HORIZONTAL; - this.gbConstraints.gridx = GridBagConstraints.REMAINDER; - this.gbConstraints.gridy = GridBagConstraints.RELATIVE; - this.gbConstraints.weightx = 1.0; - this.gbConstraints.weighty = 0; - - this.setLayout(new BorderLayout()); - this.add(this.listPanel, BorderLayout.CENTER); - } -}
