1 package com.quantum.view.bookmark;
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.NotConnectedException;
11 import com.quantum.sql.SQLHelper;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.ui.IViewPart;
15 import org.eclipse.ui.actions.SelectionListenerAction;
18 final class AddSchemaAction extends SelectionListenerAction {
19 private final IViewPart view;
23 public AddSchemaAction(IViewPart view) {
24 super(Messages.getString("BookmarkView.SetExtraSchemas")); //$NON-NLS-1$
26 QuantumPlugin.getImageDescriptor("add_schema.gif")); //$NON-NLS-1$
31 Bookmark bookmark = getBookmark();
32 if (bookmark != null) {
34 Vector schemas = SQLHelper.getSchemas(bookmark.getConnection());
35 AddSchemaDialog dialog = new AddSchemaDialog(this.view.getSite().getShell(), schemas);
37 if (dialog.getSelectedSchemas() != null) {
38 for (Iterator i = dialog.getSelectedSchemas().iterator(); i.hasNext();) {
39 bookmark.addSchema((String) i.next());
42 } catch (NotConnectedException e) {
47 protected Bookmark getBookmark() {
48 List list = getSelectedNonResources();
49 return (list.size() > 0) ? ((BookmarkNode) list.get(0)).getBookmark() : null;
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();