1 package com.quantum.view.bookmark;
3 import java.util.Iterator;
5 import com.quantum.QuantumPlugin;
6 import com.quantum.actions.AddToQuickListAction;
7 import com.quantum.actions.ConnectAction;
8 import com.quantum.actions.DeleteAllRowsAction;
9 import com.quantum.actions.DeleteBookmarkAction;
10 import com.quantum.actions.DisconnectAction;
11 import com.quantum.actions.NewBookmarkAction;
12 import com.quantum.actions.NextSequenceAction;
13 import com.quantum.actions.OpenQueryAction;
14 import com.quantum.actions.PrevSequenceAction;
15 import com.quantum.actions.RefreshBookmarkAction;
16 import com.quantum.actions.RemoveFromQuickListAction;
17 import com.quantum.actions.ViewTableAction;
18 import com.quantum.actions.ViewTableDetailsAction;
19 import com.quantum.model.Bookmark;
21 import org.eclipse.jface.action.Action;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IToolBarManager;
25 import org.eclipse.jface.action.Separator;
26 import org.eclipse.jface.viewers.ISelectionProvider;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28 import org.eclipse.ui.IActionBars;
29 import org.eclipse.ui.IViewPart;
30 import org.eclipse.ui.IWorkbenchActionConstants;
31 import org.eclipse.ui.actions.ActionGroup;
32 import org.eclipse.ui.actions.ExportResourcesAction;
33 import org.eclipse.ui.actions.SelectionListenerAction;
34 import org.eclipse.ui.actions.SelectionProviderAction;
35 import org.eclipse.ui.dialogs.PropertyDialogAction;
40 public class BookmarkViewActionGroup extends ActionGroup
41 implements BookmarkClipboard {
43 private Bookmark bookmarkClipboard;
45 private Action newBookmarkAction;
47 // bookmark node actions
48 private SelectionListenerAction connectAction;
49 private SelectionListenerAction disconnectAction;
50 private SelectionListenerAction deleteBookmarkAction;
53 private SelectionListenerAction openQueryAction;
55 // Entity node actions
56 private SelectionListenerAction addToQuickListAction;
57 private SelectionListenerAction removeFromQuickListAction;
58 private SelectionListenerAction viewTableAction;
59 private SelectionListenerAction addSchemaAction;
60 private SelectionListenerAction viewTableDetailsAction;
62 private SelectionListenerAction nextSequenceAction;
63 private SelectionListenerAction previousSequenceAction;
67 private SelectionListenerAction refreshAction;
68 private SelectionListenerAction renameAction;
70 private ExportResourcesAction exportAction;
73 private SelectionProviderAction propertiesAction;
75 private SelectionListenerAction copyAction;
76 private SelectionListenerAction pasteAction;
77 private SelectionListenerAction deleteAllRowsAction;
79 private IViewPart viewPart;
81 public BookmarkViewActionGroup(
82 IViewPart viewPart, ISelectionProvider selectionProvider) {
83 this.viewPart = viewPart;
85 this.newBookmarkAction = new NewBookmarkAction(this.viewPart);
88 this.connectAction = new ConnectAction(this.viewPart);
89 this.disconnectAction = new DisconnectAction(this.viewPart);
90 this.deleteBookmarkAction = new DeleteBookmarkAction(this.viewPart);
93 this.previousSequenceAction = new PrevSequenceAction(this.viewPart);
94 this.nextSequenceAction = new NextSequenceAction(this.viewPart);
95 this.addToQuickListAction = new AddToQuickListAction(this.viewPart);
96 this.removeFromQuickListAction = new RemoveFromQuickListAction(this.viewPart);
97 this.deleteAllRowsAction = new DeleteAllRowsAction(this.viewPart);
98 this.viewTableDetailsAction = new ViewTableDetailsAction(this.viewPart);
100 this.openQueryAction = new OpenQueryAction(this.viewPart);
102 this.viewTableAction = new ViewTableAction(this.viewPart);
103 this.addSchemaAction = new AddSchemaAction(this.viewPart);
104 this.refreshAction = new RefreshBookmarkAction(this.viewPart);
105 this.renameAction = new RenameAction(this.viewPart);
106 this.copyAction = new CopyAction(this.viewPart, this, selectionProvider);
107 this.pasteAction = new PasteAction(this.viewPart, this, selectionProvider);
108 this.exportAction = new ExportResourcesAction(
109 this.viewPart.getViewSite().getWorkbenchWindow());
110 this.exportAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("export.gif"));
112 this.propertiesAction = new PropertyDialogAction(
113 this.viewPart.getSite().getShell(), selectionProvider);
118 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
120 public void fillContextMenu(IMenuManager menu) {
122 menu.add(this.newBookmarkAction);
123 menu.add(new Separator());
125 if (getStructuredSelection().size() > 0 &&
126 isEverySelectionInstanceof(BookmarkNode.class)) {
128 addToMenu(menu, this.connectAction);
129 addToMenu(menu, this.disconnectAction);
132 menu.add(new Separator());
133 menu.add(this.copyAction);
134 // TODO: paste needs to change enablement whenever something is added
136 addToMenu(menu, this.pasteAction);
137 addToMenu(menu, this.deleteBookmarkAction);
139 if (getStructuredSelection().size() == 1 &&
140 isEverySelectionInstanceof(BookmarkNode.class)) {
142 addToMenu(menu, this.renameAction);
145 menu.add(new Separator());
147 // NOTE: In Eclipse 3.0.0 M6, Export is no longer a sub-class of
148 // SelectionListenerAction.
149 this.exportAction.selectionChanged(getStructuredSelection());
150 menu.add(this.exportAction);
152 if (getStructuredSelection().size() == 1 &&
153 isEverySelectionInstanceof(BookmarkNode.class)) {
155 menu.add(new Separator());
156 addToMenu(menu, this.addSchemaAction);
159 if (isEverySelectionInstanceof(QueryNode.class)) {
160 if (getStructuredSelection().size() == 1) {
161 addToMenu(menu, this.openQueryAction);
165 if (getStructuredSelection().size() > 0 &&
166 isEverySelectionInstanceof(EntityNode.class)) {
168 menu.add(new Separator());
170 if (getStructuredSelection().size() == 1) {
171 if (((EntityNode) getStructuredSelection().getFirstElement()).isSequence()) {
172 addToMenu(menu, this.nextSequenceAction);
173 addToMenu(menu, this.previousSequenceAction);
175 addToMenu(menu, this.viewTableAction);
176 addToMenu(menu, this.deleteAllRowsAction);
177 addToMenu(menu, this.viewTableDetailsAction);
181 addToMenu(menu, this.addToQuickListAction);
182 addToMenu(menu, this.removeFromQuickListAction);
185 if (getStructuredSelection().size() == 1) {
186 menu.add(new Separator());
187 addToMenu(menu, this.refreshAction);
190 createMarkerForActionsProvidedByOtherPlugins(menu);
192 if (getStructuredSelection().size() == 1) {
193 addToMenu(menu, this.propertiesAction);
198 private void addToMenu(IMenuManager menu, SelectionListenerAction action) {
199 action.selectionChanged(getStructuredSelection());
203 private void addToMenu(IMenuManager menu, SelectionProviderAction action) {
204 action.selectionChanged(getStructuredSelection());
209 private IStructuredSelection getStructuredSelection() {
210 return (IStructuredSelection) getContext().getSelection();
213 private boolean isEverySelectionInstanceof(Class selectedClass) {
214 boolean result = true;
215 IStructuredSelection selection = getStructuredSelection();
216 for (Iterator i = selection.iterator(); result && i.hasNext(); ) {
217 Object object = i.next();
218 result &= selectedClass.isAssignableFrom(object.getClass());
224 public IAction getOpenAction() {
225 if (isEverySelectionInstanceof(BookmarkNode.class)) {
226 this.connectAction.selectionChanged(getStructuredSelection());
227 return this.connectAction.isEnabled() ? this.connectAction : null;
228 } else if (isEverySelectionInstanceof(EntityNode.class)) {
229 this.viewTableAction.selectionChanged(getStructuredSelection());
230 return this.viewTableAction.isEnabled() ? this.viewTableAction : null;
231 } else if (isEverySelectionInstanceof(QueryNode.class)) {
232 this.openQueryAction.selectionChanged(getStructuredSelection());
233 return this.openQueryAction.isEnabled() ? this.openQueryAction : null;
239 private void createMarkerForActionsProvidedByOtherPlugins(IMenuManager mgr) {
240 mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
241 mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
242 mgr.add(new Separator());
244 public void fillActionBars(IActionBars actionBars) {
245 IToolBarManager toolBar = actionBars.getToolBarManager();
246 toolBar.add(this.newBookmarkAction);
248 actionBars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, this.copyAction);
253 * @see com.quantum.view.bookmark.BookmarkClipboard#setBookmark(com.quantum.model.Bookmark)
255 public void setBookmark(Bookmark bookmark) {
256 this.bookmarkClipboard = bookmark;
261 * @see com.quantum.view.bookmark.BookmarkClipboard#getBookmark()
263 public Bookmark getBookmark() {
264 return this.bookmarkClipboard;