1 package com.quantum.actions;
3 import java.util.Iterator;
5 import java.util.Vector;
7 import com.quantum.Messages;
8 import com.quantum.QuantumPlugin;
9 import com.quantum.model.Bookmark;
10 import com.quantum.model.ConnectionException;
11 import com.quantum.view.bookmark.BookmarkNode;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.ui.IViewPart;
15 import org.eclipse.ui.actions.SelectionListenerAction;
18 * Disconnects from the database
22 public class DisconnectAction extends SelectionListenerAction {
23 private IViewPart view;
24 private List selections = new Vector();
29 public DisconnectAction(IViewPart view) {
30 super(Messages.getString(DisconnectAction.class.getName() + ".text"));
33 QuantumPlugin.getImageDescriptor("disconnect.gif")); //$NON-NLS-1$
38 for (Iterator i = this.selections.iterator(); i.hasNext();) {
39 Bookmark bookmark = (Bookmark) i.next();
41 bookmark.disconnect();
42 } catch (ConnectionException e) {
46 updateStatusLine(getMessage("message"));
49 private String getMessage(String key) {
50 return Messages.getString(getClass().getName() + "." + key);
54 * Updates the message shown in the status line.
56 * @param message the message to display
58 protected void updateStatusLine(String message) {
59 this.view.getViewSite().getActionBars().getStatusLineManager().setMessage(message);
66 public boolean updateSelection(IStructuredSelection selection) {
67 boolean enabled = super.updateSelection(selection);
68 this.selections.clear();
69 for (Iterator i = selection.iterator(); enabled && i.hasNext(); ) {
70 Object object = i.next();
71 if (object instanceof BookmarkNode) {
72 BookmarkNode node = (BookmarkNode) object;
73 this.selections.add(node.getBookmark());
74 enabled &= node.getBookmark().isConnected();