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 viewTableDetailsAction;
61 private SelectionListenerAction nextSequenceAction;
62 private SelectionListenerAction previousSequenceAction;
66 private SelectionListenerAction refreshAction;
67 private SelectionListenerAction renameAction;
69 private ExportResourcesAction exportAction;
72 private SelectionProviderAction propertiesAction;
74 private SelectionListenerAction copyAction;
75 private SelectionListenerAction pasteAction;
76 private SelectionListenerAction deleteAllRowsAction;
78 private IViewPart viewPart;
80 public BookmarkViewActionGroup(
81 IViewPart viewPart, ISelectionProvider selectionProvider) {
82 this.viewPart = viewPart;
84 this.newBookmarkAction = new NewBookmarkAction(this.viewPart);
87 this.connectAction = new ConnectAction(this.viewPart);
88 this.disconnectAction = new DisconnectAction(this.viewPart);
89 this.deleteBookmarkAction = new DeleteBookmarkAction(this.viewPart);
92 this.previousSequenceAction = new PrevSequenceAction(this.viewPart);
93 this.nextSequenceAction = new NextSequenceAction(this.viewPart);
94 this.addToQuickListAction = new AddToQuickListAction(this.viewPart);
95 this.removeFromQuickListAction = new RemoveFromQuickListAction(this.viewPart);
96 this.deleteAllRowsAction = new DeleteAllRowsAction(this.viewPart);
97 this.viewTableDetailsAction = new ViewTableDetailsAction(this.viewPart);
99 this.openQueryAction = new OpenQueryAction(this.viewPart);
101 this.viewTableAction = new ViewTableAction(this.viewPart);
102 this.refreshAction = new RefreshBookmarkAction(this.viewPart);
103 this.renameAction = new RenameAction(this.viewPart);
104 this.copyAction = new CopyAction(this.viewPart, this, selectionProvider);
105 this.pasteAction = new PasteAction(this.viewPart, this, selectionProvider);
106 this.exportAction = new ExportResourcesAction(
107 this.viewPart.getViewSite().getWorkbenchWindow());
108 this.exportAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("export.gif"));
110 this.propertiesAction = new PropertyDialogAction(
111 this.viewPart.getSite().getShell(), selectionProvider);
116 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
118 public void fillContextMenu(IMenuManager menu) {
120 menu.add(this.newBookmarkAction);
121 menu.add(new Separator());
123 if (getStructuredSelection().size() > 0 &&
124 isEverySelectionInstanceof(BookmarkNode.class)) {
126 addToMenu(menu, this.connectAction);
127 addToMenu(menu, this.disconnectAction);
130 menu.add(new Separator());
131 menu.add(this.copyAction);
132 // TODO: paste needs to change enablement whenever something is added
134 addToMenu(menu, this.pasteAction);
135 addToMenu(menu, this.deleteBookmarkAction);
137 if (getStructuredSelection().size() == 1 &&
138 isEverySelectionInstanceof(BookmarkNode.class)) {
140 addToMenu(menu, this.renameAction);
143 menu.add(new Separator());
145 // NOTE: In Eclipse 3.0.0 M6, Export is no longer a sub-class of
146 // SelectionListenerAction.
147 this.exportAction.selectionChanged(getStructuredSelection());
148 menu.add(this.exportAction);
150 if (getStructuredSelection().size() == 1 &&
151 isEverySelectionInstanceof(BookmarkNode.class)) {
154 if (isEverySelectionInstanceof(QueryNode.class)) {
155 if (getStructuredSelection().size() == 1) {
156 addToMenu(menu, this.openQueryAction);
160 if (getStructuredSelection().size() > 0 &&
161 isEverySelectionInstanceof(EntityNode.class)) {
163 menu.add(new Separator());
165 if (getStructuredSelection().size() == 1) {
166 if (((EntityNode) getStructuredSelection().getFirstElement()).isSequence()) {
167 addToMenu(menu, this.nextSequenceAction);
168 addToMenu(menu, this.previousSequenceAction);
170 addToMenu(menu, this.viewTableAction);
171 addToMenu(menu, this.deleteAllRowsAction);
172 addToMenu(menu, this.viewTableDetailsAction);
176 addToMenu(menu, this.addToQuickListAction);
177 addToMenu(menu, this.removeFromQuickListAction);
180 if (getStructuredSelection().size() == 1) {
181 menu.add(new Separator());
182 addToMenu(menu, this.refreshAction);
185 createMarkerForActionsProvidedByOtherPlugins(menu);
187 if (getStructuredSelection().size() == 1) {
188 addToMenu(menu, this.propertiesAction);
193 private void addToMenu(IMenuManager menu, SelectionListenerAction action) {
194 action.selectionChanged(getStructuredSelection());
198 private void addToMenu(IMenuManager menu, SelectionProviderAction action) {
199 action.selectionChanged(getStructuredSelection());
204 private IStructuredSelection getStructuredSelection() {
205 return (IStructuredSelection) getContext().getSelection();
208 private boolean isEverySelectionInstanceof(Class selectedClass) {
209 boolean result = true;
210 IStructuredSelection selection = getStructuredSelection();
211 for (Iterator i = selection.iterator(); result && i.hasNext(); ) {
212 Object object = i.next();
213 result &= selectedClass.isAssignableFrom(object.getClass());
219 public IAction getOpenAction() {
220 if (isEverySelectionInstanceof(BookmarkNode.class)) {
221 this.connectAction.selectionChanged(getStructuredSelection());
222 return this.connectAction.isEnabled() ? this.connectAction : null;
223 } else if (isEverySelectionInstanceof(EntityNode.class)) {
224 this.viewTableAction.selectionChanged(getStructuredSelection());
225 return this.viewTableAction.isEnabled() ? this.viewTableAction : null;
226 } else if (isEverySelectionInstanceof(QueryNode.class)) {
227 this.openQueryAction.selectionChanged(getStructuredSelection());
228 return this.openQueryAction.isEnabled() ? this.openQueryAction : null;
234 private void createMarkerForActionsProvidedByOtherPlugins(IMenuManager mgr) {
235 mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
236 mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
237 mgr.add(new Separator());
239 public void fillActionBars(IActionBars actionBars) {
240 IToolBarManager toolBar = actionBars.getToolBarManager();
241 toolBar.add(this.newBookmarkAction);
243 actionBars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, this.copyAction);
248 * @see com.quantum.view.bookmark.BookmarkClipboard#setBookmark(com.quantum.model.Bookmark)
250 public void setBookmark(Bookmark bookmark) {
251 this.bookmarkClipboard = bookmark;
256 * @see com.quantum.view.bookmark.BookmarkClipboard#getBookmark()
258 public Bookmark getBookmark() {
259 return this.bookmarkClipboard;