1 package com.quantum.view.driver;
5 import com.quantum.ImageStore;
6 import com.quantum.Messages;
7 import com.quantum.model.Bookmark;
8 import com.quantum.model.BookmarkCollection;
9 import com.quantum.model.JDBCDriver;
11 import org.eclipse.jface.dialogs.MessageDialog;
12 import org.eclipse.jface.viewers.ISelectionProvider;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.ui.IViewPart;
16 import org.eclipse.ui.actions.SelectionListenerAction;
19 * This action deletes JDBC Drivers from the JDBC Driver collection.
23 public class DeleteDriverAction extends SelectionListenerAction {
25 private final IViewPart viewPart;
30 protected DeleteDriverAction(IViewPart viewPart, ISelectionProvider selectionProvider) {
31 super(Messages.getString(DeleteDriverAction.class, "text"));
32 this.viewPart = viewPart;
33 selectionProvider.addSelectionChangedListener(this);
34 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.DELETE));
38 JDBCDriver driver = getJDBCDriver();
41 Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks();
42 boolean found = false;
43 for (int i = 0, length = bookmarks == null ? 0 : bookmarks.length;
44 driver != null && !found && i < length; i++) {
45 found |= driver.equals(bookmarks[i].getJDBCDriver());
49 MessageDialog.openWarning(getShell(),
50 Messages.getString(DeleteDriverAction.class, "failed"),
51 Messages.getString(DeleteDriverAction.class, "inUse"));
53 if (MessageDialog.openConfirm(getShell(),
54 Messages.getString(DeleteDriverAction.class, "confirm"),
55 Messages.getString(DeleteDriverAction.class, "confirmText",
56 new Object[] { driver.getName() }))) {
58 if (!BookmarkCollection.getInstance().removeDriver(driver)) {
59 MessageDialog.openWarning(getShell(),
60 Messages.getString(DeleteDriverAction.class, "failed"),
61 Messages.getString(DeleteDriverAction.class, "cant"));
71 private Shell getShell() {
72 return this.viewPart.getViewSite().getShell();
78 private JDBCDriver getJDBCDriver() {
79 List list = getSelectedNonResources();
80 return list == null || list.size() == 0 ? null : (JDBCDriver) list.get(0);
83 protected boolean updateSelection(IStructuredSelection selection) {
84 return selection != null && !selection.isEmpty();