Minor changes in pages design.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / bookmark / DropEntityAction.java
1 package com.quantum.view.bookmark;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import com.quantum.Messages;
8 import com.quantum.actions.BaseExecuteAction;
9 import com.quantum.model.Bookmark;
10 import com.quantum.model.Entity;
11 import com.quantum.model.EntityHolder;
12 import com.quantum.sql.parser.DropEntityStatement;
13 import com.quantum.wizards.sql.DropEntityWizardPage;
14 import com.quantum.wizards.sql.SQLStatementWizard;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jface.action.IStatusLineManager;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.jface.wizard.WizardDialog;
20 import org.eclipse.jface.wizard.WizardPage;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.IViewPart;
23
24
25 /**
26  * Drop a table.
27  * 
28  * @author BC Holmes
29  */
30 public class DropEntityAction extends BaseExecuteAction {
31
32         private final IViewPart view;
33         private DropEntityStatement statement = new DropEntityStatement();
34
35         public DropEntityAction(IViewPart view) {
36                 this.view = view;
37                 setText(Messages.getString(getClass(), "text"));
38         }
39         
40         public void run() {
41                 Entity entity = getEntity();
42                 if (entity != null) {
43                         this.statement.setTableName(entity.getQuotedTableName());
44                         this.statement.setType(entity.getType());
45                 }
46                 
47                 DropEntityWizardPage page = new DropEntityWizardPage("page1", this.statement);
48                 SQLStatementWizard wizard = new SQLStatementWizard(new WizardPage[] { page }, this.statement);
49                 
50                 WizardDialog dialog = new WizardDialog(this.view.getViewSite().getShell(), wizard);
51                 if (WizardDialog.OK == dialog.open()) {
52                         super.run();
53                 }
54         }
55         protected Shell getShell() {
56                 return this.view.getViewSite().getShell();
57         }
58
59         protected Bookmark getBookmark() {
60                 Entity entity = getEntity();
61                 return entity != null ? entity.getBookmark() : super.getBookmark();
62         }
63         protected List getQueries() throws IOException, CoreException {
64                 List list = new ArrayList();
65                 list.add(this.statement.toString());
66                 return list;
67         }
68         
69         protected Entity getEntity() {
70                 List list = getSelectedNonResources();
71                 return list == null || list.isEmpty() ? null : ((EntityHolder) list.get(0)).getEntity();
72         }
73
74         protected IStatusLineManager getStatusLineManager() {
75                 return this.view.getViewSite().getActionBars().getStatusLineManager();
76         }
77
78         protected boolean updateSelection(IStructuredSelection selection) {
79                 return !selection.isEmpty();
80         }
81 }