package com.quantum.view.bookmark; 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.NotConnectedException; import com.quantum.sql.SQLHelper; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IViewPart; import org.eclipse.ui.actions.SelectionListenerAction; final class AddSchemaAction extends SelectionListenerAction { private final IViewPart view; /** * @param BookmarkView */ public AddSchemaAction(IViewPart view) { super(Messages.getString("BookmarkView.SetExtraSchemas")); //$NON-NLS-1$ setImageDescriptor( QuantumPlugin.getImageDescriptor("add_schema.gif")); //$NON-NLS-1$ this.view = view; } public void run() { Bookmark bookmark = getBookmark(); if (bookmark != null) { try { Vector schemas = SQLHelper.getSchemas(bookmark.getConnection()); AddSchemaDialog dialog = new AddSchemaDialog(this.view.getSite().getShell(), schemas); dialog.open(); if (dialog.getSelectedSchemas() != null) { for (Iterator i = dialog.getSelectedSchemas().iterator(); i.hasNext();) { bookmark.addSchema((String) i.next()); } } } catch (NotConnectedException e) { } } } protected Bookmark getBookmark() { List list = getSelectedNonResources(); return (list.size() > 0) ? ((BookmarkNode) list.get(0)).getBookmark() : null; } protected boolean updateSelection(IStructuredSelection selection) { boolean enabled = super.updateSelection(selection) & selection.size() == 1 & (selection.getFirstElement() instanceof BookmarkNode); return enabled & getBookmark().isConnected(); } }