RSS news reader; initially copied from "all the news"
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / RefreshBookmarkAction.java
1 package com.quantum.actions;
2
3 import java.sql.SQLException;
4 import java.util.Iterator;
5 import java.util.List;
6
7 import com.quantum.ImageStore;
8 import com.quantum.Messages;
9 import com.quantum.model.NotConnectedException;
10 import com.quantum.ui.dialog.ExceptionDisplayDialog;
11 import com.quantum.ui.dialog.SQLExceptionDialog;
12 import com.quantum.view.bookmark.TreeNode;
13
14 import org.eclipse.ui.IViewPart;
15 import org.eclipse.ui.actions.SelectionListenerAction;
16
17 /**
18  * @author root
19  */
20 public class RefreshBookmarkAction extends SelectionListenerAction {
21     private IViewPart view;
22         public RefreshBookmarkAction(IViewPart view) {
23         super(Messages.getString(RefreshBookmarkAction.class, "text"));
24                 this.view = view;
25         setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.REFRESH));
26         }
27
28         public void run() {
29                 List list = getSelectedNonResources();
30         for (Iterator i = list.iterator(); i.hasNext(); ) {
31             Object object = i.next();
32             if (object != null && object instanceof TreeNode) {
33                 try {
34                         ((TreeNode) object).reload();
35                 } catch (NotConnectedException e) {
36                         handleException(e);
37                 } catch (SQLException e) {
38                         handleException(e);
39                 }
40             }
41         }
42         }
43
44         /**
45          * @param e
46          */
47         private void handleException(Throwable t) {
48                 if (t instanceof SQLException) {
49                         SQLExceptionDialog.openException(
50                                         this.view.getSite().getShell(), null, (SQLException) t);
51                 } else {
52                         ExceptionDisplayDialog.openError(
53                                         this.view.getSite().getShell(), null, null, t);
54                 }
55         }
56 }