synchronized from quantum plugin
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / PrevSequenceAction.java
1 /*
2  * Created on 22-jul-2003
3  *
4  */
5 package com.quantum.actions;
6
7 import com.quantum.Messages;
8 import com.quantum.QuantumPlugin;
9 import com.quantum.adapters.AdapterFactory;
10 import com.quantum.adapters.DatabaseAdapter;
11 import com.quantum.model.Bookmark;
12 import com.quantum.sql.SQLResults;
13 import com.quantum.view.ViewHelper;
14 import com.quantum.view.bookmark.EntityNode;
15 import com.quantum.view.tableview.TableView;
16
17 import org.eclipse.ui.IViewPart;
18
19 public class PrevSequenceAction extends BaseSequenceAction {
20         /**
21      * @param text
22      * @param view
23      */
24     public PrevSequenceAction(IViewPart view) {
25         super(Messages.getString(PrevSequenceAction.class.getName() + ".text"), view);
26         setImageDescriptor(QuantumPlugin.getImageDescriptor("grid.gif"));
27     }
28
29     public void run() {
30                 EntityNode node = getEntityNode();
31                 if (((EntityNode) node).isSequence()) {
32             EntityNode sequence = (EntityNode) node;
33                         Bookmark bookmark = sequence.getBookmark();
34                         DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(
35                 bookmark.getType());
36                         if (adapter == null) return;
37                         String name = sequence.getName();
38                         String query = adapter.getPrevValue(name, sequence.getEntity().getSchema());
39                         SQLResults results = ViewHelper.tryGetResults(view, getConnection(), query);
40                         if (results != null && ! results.isError()) 
41                                 TableView.getInstance().loadQuery(bookmark, results);
42                 }
43         }
44 }