1 package com.quantum.actions;
3 import java.sql.SQLException;
4 import java.util.Iterator;
6 import java.util.Vector;
8 import com.quantum.ImageStore;
9 import com.quantum.Messages;
10 import com.quantum.model.Bookmark;
11 import com.quantum.ui.dialog.SQLExceptionDialog;
12 import com.quantum.view.bookmark.BookmarkNode;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.ui.IViewPart;
16 import org.eclipse.ui.actions.SelectionListenerAction;
19 * Disconnects from the database
23 public class DisconnectAction extends SelectionListenerAction {
24 private IViewPart view;
25 private List selections = new Vector();
30 public DisconnectAction(IViewPart view) {
31 super(Messages.getString(DisconnectAction.class.getName() + ".text"));
34 ImageStore.getImageDescriptor(ImageStore.DISCONNECT));
39 for (Iterator i = this.selections.iterator(); i.hasNext(); ) {
40 Bookmark bookmark = (Bookmark) i.next();
42 bookmark.disconnect();
43 } catch (SQLException e) {
44 SQLExceptionDialog.openException(
45 this.view.getViewSite().getShell(), bookmark, e);
48 updateStatusLine(getMessage("message"));
51 private String getMessage(String key) {
52 return Messages.getString(getClass().getName() + "." + key);
56 * Updates the message shown in the status line.
58 * @param message the message to display
60 protected void updateStatusLine(String message) {
61 this.view.getViewSite().getActionBars().getStatusLineManager().setMessage(message);
68 public boolean updateSelection(IStructuredSelection selection) {
69 boolean enabled = super.updateSelection(selection);
70 this.selections.clear();
71 for (Iterator i = selection.iterator(); enabled && i.hasNext(); ) {
72 Object object = i.next();
73 if (object instanceof BookmarkNode) {
74 BookmarkNode node = (BookmarkNode) object;
75 this.selections.add(node.getBookmark());
76 enabled &= node.getBookmark().isConnected();