X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/DisconnectAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/DisconnectAction.java new file mode 100644 index 0000000..7966a08 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/DisconnectAction.java @@ -0,0 +1,81 @@ +package com.quantum.actions; + +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import com.quantum.Messages; +import com.quantum.QuantumPlugin; +import com.quantum.model.Bookmark; +import com.quantum.model.ConnectionException; +import com.quantum.view.bookmark.BookmarkNode; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.SelectionListenerAction; + +/** + * Disconnects from the database + * + * @author root + */ +public class DisconnectAction extends SelectionListenerAction { + private IViewPart view; + private List selections = new Vector(); + + /** + * @param text + */ + public DisconnectAction(IViewPart view) { + super(Messages.getString(DisconnectAction.class.getName() + ".text")); + this.view = view; + setImageDescriptor( + QuantumPlugin.getImageDescriptor("disconnect.gif")); //$NON-NLS-1$ + } + + + public void run() { + for (Iterator i = this.selections.iterator(); i.hasNext();) { + Bookmark bookmark = (Bookmark) i.next(); + try { + bookmark.disconnect(); + } catch (ConnectionException e) { + e.printStackTrace(); + } + } + updateStatusLine(getMessage("message")); + } + + private String getMessage(String key) { + return Messages.getString(getClass().getName() + "." + key); + } + + /** + * Updates the message shown in the status line. + * + * @param message the message to display + */ + protected void updateStatusLine(String message) { + this.view.getViewSite().getActionBars().getStatusLineManager().setMessage(message); + } + + + /** + * + */ + public boolean updateSelection(IStructuredSelection selection) { + boolean enabled = super.updateSelection(selection); + this.selections.clear(); + for (Iterator i = selection.iterator(); enabled && i.hasNext(); ) { + Object object = i.next(); + if (object instanceof BookmarkNode) { + BookmarkNode node = (BookmarkNode) object; + this.selections.add(node.getBookmark()); + enabled &= node.getBookmark().isConnected(); + } else { + enabled = false; + } + } + return enabled; + } +}