misc changes
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / bookmark / AddSchemaAction.java
1 package com.quantum.view.bookmark;
2
3 import java.util.Iterator;
4 import java.util.List;
5 import java.util.Vector;
6
7 import com.quantum.Messages;
8 import com.quantum.QuantumPlugin;
9 import com.quantum.model.Bookmark;
10 import com.quantum.model.NotConnectedException;
11 import com.quantum.sql.SQLHelper;
12
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.ui.IViewPart;
15 import org.eclipse.ui.actions.SelectionListenerAction;
16
17
18 final class AddSchemaAction extends SelectionListenerAction {
19     private final IViewPart view;
20     /**
21      * @param BookmarkView
22      */
23     public AddSchemaAction(IViewPart view) {
24         super(Messages.getString("BookmarkView.SetExtraSchemas")); //$NON-NLS-1$
25         setImageDescriptor(
26             QuantumPlugin.getImageDescriptor("add_schema.gif")); //$NON-NLS-1$
27         this.view = view;
28     }
29     
30     public void run() {
31         Bookmark bookmark = getBookmark();
32         if (bookmark != null) {
33             try {
34                         Vector schemas = SQLHelper.getSchemas(bookmark.getConnection());
35                         AddSchemaDialog dialog = new AddSchemaDialog(this.view.getSite().getShell(), schemas);
36                         dialog.open();
37                         if (dialog.getSelectedSchemas() != null) {
38                     for (Iterator i = dialog.getSelectedSchemas().iterator(); i.hasNext();) {
39                                         bookmark.addSchema((String) i.next());
40                     }
41                         }
42             } catch (NotConnectedException e) {
43             }
44         }
45     }
46     
47     protected Bookmark getBookmark() {
48         List list = getSelectedNonResources();
49         return (list.size() > 0) ? ((BookmarkNode) list.get(0)).getBookmark() : null;
50     }
51     
52     protected boolean updateSelection(IStructuredSelection selection) {
53         boolean enabled = super.updateSelection(selection) &
54             selection.size() == 1 & 
55             (selection.getFirstElement() instanceof BookmarkNode);
56         return enabled & getBookmark().isConnected();
57     }
58 }