1 package com.quantum.view.bookmark;
3 import java.util.Iterator;
5 import com.quantum.ImageStore;
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;
20 import com.quantum.util.versioning.VersioningHelper;
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.action.IMenuManager;
25 import org.eclipse.jface.action.IToolBarManager;
26 import org.eclipse.jface.action.Separator;
27 import org.eclipse.jface.viewers.ISelectionProvider;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.ui.IActionBars;
30 import org.eclipse.ui.IViewPart;
31 import org.eclipse.ui.IWorkbenchActionConstants;
32 import org.eclipse.ui.actions.ActionGroup;
33 import org.eclipse.ui.actions.ExportResourcesAction;
34 import org.eclipse.ui.actions.SelectionListenerAction;
35 import org.eclipse.ui.actions.SelectionProviderAction;
36 import org.eclipse.ui.dialogs.PropertyDialogAction;
41 public class BookmarkViewActionGroup extends ActionGroup
42 implements BookmarkClipboard {
44 private Bookmark bookmarkClipboard;
46 private Action newBookmarkAction;
48 // bookmark node actions
49 private SelectionListenerAction connectAction;
50 private SelectionListenerAction disconnectAction;
51 private SelectionListenerAction deleteBookmarkAction;
54 private SelectionListenerAction openQueryAction;
56 // Entity node actions
57 private SelectionListenerAction addToQuickListAction;
58 private SelectionListenerAction removeFromQuickListAction;
59 private SelectionListenerAction viewTableAction;
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.refreshAction = new RefreshBookmarkAction(this.viewPart);
104 this.renameAction = new RenameAction(this.viewPart);
105 this.copyAction = new CopyAction(this.viewPart, this, selectionProvider);
106 this.pasteAction = new PasteAction(this.viewPart, this, selectionProvider);
107 this.exportAction = VersioningHelper.createExportResourcesAction(
108 this.viewPart.getViewSite().getWorkbenchWindow());
109 this.exportAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.EXPORT));
111 this.propertiesAction = new PropertyDialogAction(
112 this.viewPart.getSite().getShell(), selectionProvider);
117 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
119 public void fillContextMenu(IMenuManager menu) {
121 menu.add(this.newBookmarkAction);
122 menu.add(new Separator());
124 if (getStructuredSelection().size() > 0 &&
125 isEverySelectionInstanceof(BookmarkNode.class)) {
127 addToMenu(menu, this.connectAction);
128 addToMenu(menu, this.disconnectAction);
131 menu.add(new Separator());
132 menu.add(this.copyAction);
133 // TODO: paste needs to change enablement whenever something is added
135 addToMenu(menu, this.pasteAction);
136 addToMenu(menu, this.deleteBookmarkAction);
138 if (getStructuredSelection().size() == 1 &&
139 isEverySelectionInstanceof(BookmarkNode.class)) {
141 addToMenu(menu, this.renameAction);
144 menu.add(new Separator());
146 // NOTE: In Eclipse 3.0.0 M6, Export is no longer a sub-class of
147 // SelectionListenerAction.
148 if (this.exportAction != null) {
149 this.exportAction.selectionChanged(getStructuredSelection());
150 menu.add(this.exportAction);
153 if (getStructuredSelection().size() == 1 &&
154 isEverySelectionInstanceof(BookmarkNode.class)) {
157 if (isEverySelectionInstanceof(QueryNode.class)) {
158 if (getStructuredSelection().size() == 1) {
159 addToMenu(menu, this.openQueryAction);
163 if (getStructuredSelection().size() > 0 &&
164 isEverySelectionInstanceof(EntityNode.class)) {
166 menu.add(new Separator());
168 if (getStructuredSelection().size() == 1) {
169 if (((EntityNode) getStructuredSelection().getFirstElement()).isSequence()) {
170 addToMenu(menu, this.nextSequenceAction);
171 addToMenu(menu, this.previousSequenceAction);
173 addToMenu(menu, this.viewTableAction);
174 addToMenu(menu, this.deleteAllRowsAction);
175 addToMenu(menu, this.viewTableDetailsAction);
179 addToMenu(menu, this.addToQuickListAction);
180 addToMenu(menu, this.removeFromQuickListAction);
183 if (getStructuredSelection().size() == 1) {
184 menu.add(new Separator());
185 addToMenu(menu, this.refreshAction);
188 createMarkerForActionsProvidedByOtherPlugins(menu);
190 if (getStructuredSelection().size() == 1) {
191 addToMenu(menu, this.propertiesAction);
196 private void addToMenu(IMenuManager menu, SelectionListenerAction action) {
197 action.selectionChanged(getStructuredSelection());
201 private void addToMenu(IMenuManager menu, SelectionProviderAction action) {
202 action.selectionChanged(getStructuredSelection());
207 private IStructuredSelection getStructuredSelection() {
208 return (IStructuredSelection) getContext().getSelection();
211 private boolean isEverySelectionInstanceof(Class selectedClass) {
212 boolean result = true;
213 IStructuredSelection selection = getStructuredSelection();
214 for (Iterator i = selection.iterator(); result && i.hasNext(); ) {
215 Object object = i.next();
216 result &= selectedClass.isAssignableFrom(object.getClass());
222 public IAction getOpenAction() {
223 if (isEverySelectionInstanceof(BookmarkNode.class)) {
224 this.connectAction.selectionChanged(getStructuredSelection());
225 return this.connectAction.isEnabled() ? this.connectAction : null;
226 } else if (isEverySelectionInstanceof(EntityNode.class)) {
227 this.viewTableAction.selectionChanged(getStructuredSelection());
228 return this.viewTableAction.isEnabled() ? this.viewTableAction : null;
229 } else if (isEverySelectionInstanceof(QueryNode.class)) {
230 this.openQueryAction.selectionChanged(getStructuredSelection());
231 return this.openQueryAction.isEnabled() ? this.openQueryAction : null;
237 private void createMarkerForActionsProvidedByOtherPlugins(IMenuManager mgr) {
238 mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
239 mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
240 mgr.add(new Separator());
242 public void fillActionBars(IActionBars actionBars) {
243 IToolBarManager toolBar = actionBars.getToolBarManager();
244 toolBar.add(this.newBookmarkAction);
246 actionBars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, this.copyAction);
251 * @see com.quantum.view.bookmark.BookmarkClipboard#setBookmark(com.quantum.model.Bookmark)
253 public void setBookmark(Bookmark bookmark) {
254 this.bookmarkClipboard = bookmark;
259 * @see com.quantum.view.bookmark.BookmarkClipboard#getBookmark()
261 public Bookmark getBookmark() {
262 return this.bookmarkClipboard;